I have developed a search tool using PHP. The uses what's typed into a search box to replace part of a URL.
I am wondering if anyone can help me add IF statements to this function.
The user can search for ISBN numbers, which have to be 10 characters long. I would like a feature that tells them this if they don't type in a valid ISBN number.
I don't think this is possible, but is there any way for the site to display a "no results found" message when the URL returns a blank message? - It's connected to an online book database and at the minute, a blank screen is displayed if there are no results found in the database.
Another quick question refers to the results output. I have managed to take the XML and turn it into a nice neat table. is there a way to add a "save to excel" option? - I would like to allow the user to search for book details and update an exisiting Excel file with each result.
Hope this isn't too complicated.
Code for the functions are below:
Expand|Select|Wrap|Line Numbers
- <!-- ISBN Search -->
- <form method="post" action="isbnresults.php">
- <center>
- <input type="text" size='50' name="isbn_no" />
- <input type="submit" value="Search ISBN" />
- </center>
- </form>
- <!-- End of ISBN Search -->
- <?php
- /* FETCH AND PROCESS XML DATA */
- // Load the XML from source
- $xml = file_get_contents('http://isbndb.com//api//books.xml?access_key=YSG2I2WU&index1=isbn&value1='.urlencode($_POST['isbn_no']));
- // Parse the XML to form an object
- $tree = simplexml_load_string($xml);
- // Get a list of book objects
- $books = $tree->xpath('/ISBNdb/BookList/BookData');
- /* MAKE INTO TABLE */
- // Table Layout
- $html = '<table border="1" cellspacing="0" cellpadding="2">';
- // Perform an action for each book
- foreach($books as $book) {
- $html .=
- '<tr>
- <td align="center" bgcolor="darkturquoise">
- <font face="calibri" color="white"><b>Book Title:</b></font></td>
- <td>'.$book->Title.'</td>
- <<td align="center" bgcolor="darkturquoise">
- <font face="calibri" color="white"><b>Author:</b></font></td>
- <td>'.$book->AuthorsText.'</td>
- <td align="center" bgcolor="darkturquoise">
- <font face="calibri" color="white"><b>Publisher:</b></font></td>
- <td>'.$book->PublisherText.'</td>
- </tr>';
- }
- $html .= '</table>';
- echo $html;
- ?>