Jump to content
Larry Ullman's Book Forums

Recommended Posts

I'm trying to incorporate isbn db api in a php script. With the api and a key, it is easy to get a book detail either by isbn or title or author. I want to give a search box where user can enter either title, author or isbn and the script should return related items. I don't understand how to incorporate all 3 different searches in a single form. Following code return either one, not all 3 of them.

 

 

if(isset($_GET['submitted']))

{

if(!empty($_GET['searchterm']))

{

$isbnQuery = $_GET['searchterm']; //searchterm. Is it title, isbn or author?

$isbnTitle = $_GET['searchterm']; //same searchterm is assigned to title, but if used this way then it won't load proper xml file from isbn db api.

}

 

//$isbnData is xml file.

//$isbnQuery is the isbn number you are interested in.

 

$isbnData ="http://isbndb.com/api/books.xml?access_key=mk&index1=isbn&results=details&value1=$isbnQuery";

 

$isbnTitles = "http://isbndb.com/api/books.xml?access_key=mk&results=details&index1=title&value1=$isbnTitle";

 

$xmlData = simplexml_load_file($isbnData) or die("Error"); //load xml file according to received searchterm.

 

//display data. }

else { //show form:

<form name="isbn" method="get" action="isbn.php" accept-charset="utf-8">

<p><valign = "center"><label for "searchterm">Enter title, author or ISBN to select your book.</label></p>

<p><valign = "center"><input type="text" size="30" name="searchterm" value=" " />

<input type="submit" name="submit" value="Search" />

<input type="hidden" name="submitted" value="TRUE" />

</form>

 

How to check which xml file is loaded? How to determine whether the user has entered isbn, title or author?

There is only one text input on the form which can accept either isbn, title or author(all of which are strings types). So I can't figure out what to check and how to check?

  • Upvote 1
Link to comment
Share on other sites

From just scanning the ISBN DB API documentation, it looks like you should investigate the data provided. If it's in the format of an ISBN, you'd send a request that indicates you're providing an ISBN. Otherwise, you'd send a "combined" request, that will use the data to search both titles and authors.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...