sonal Posted December 24, 2011 Share Posted December 24, 2011 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? 1 Link to comment Share on other sites More sharing options...
rob Posted December 24, 2011 Share Posted December 24, 2011 You could use radio buttons or a select list and have the user specify what kind of search it is. 2 Link to comment Share on other sites More sharing options...
sonal Posted December 27, 2011 Author Share Posted December 27, 2011 Thanks for reply. But here I need to keep just one text input, which can be used to search book details based on either isbn, title or author. I want to put a search option just like that there in isbndb website. Link to comment Share on other sites More sharing options...
Larry Posted December 28, 2011 Share Posted December 28, 2011 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts