473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can you add IF statements to this piece of PHP code?

4
Hi,

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
  1.  
  2. <!-- ISBN Search -->
  3.       <form method="post" action="isbnresults.php"> 
  4.         <center>
  5.         <input type="text" size='50' name="isbn_no" /> 
  6.         <input type="submit" value="Search ISBN" /> 
  7.         </center>
  8.     </form> 
  9.         <!-- End of ISBN Search -->
  10.  
  11. <?php
  12.  
  13. /* FETCH AND PROCESS XML DATA */
  14.  
  15. // Load the XML from source
  16. $xml = file_get_contents('http://isbndb.com//api//books.xml?access_key=YSG2I2WU&index1=isbn&value1='.urlencode($_POST['isbn_no'])); 
  17.  
  18. // Parse the XML to form an object
  19. $tree = simplexml_load_string($xml);
  20.  
  21. // Get a list of book objects
  22. $books = $tree->xpath('/ISBNdb/BookList/BookData');
  23.  
  24.  
  25. /* MAKE INTO TABLE */
  26. // Table Layout
  27. $html = '<table border="1" cellspacing="0" cellpadding="2">';
  28.  
  29. // Perform an action for each book
  30. foreach($books as $book) {
  31. $html .= 
  32.  
  33. '<tr>
  34.     <td align="center" bgcolor="darkturquoise"> 
  35.     <font face="calibri" color="white"><b>Book Title:</b></font></td>
  36.     <td>'.$book->Title.'</td> 
  37.     <<td align="center" bgcolor="darkturquoise"> 
  38.     <font face="calibri" color="white"><b>Author:</b></font></td>
  39.     <td>'.$book->AuthorsText.'</td>
  40.     <td align="center" bgcolor="darkturquoise"> 
  41.     <font face="calibri" color="white"><b>Publisher:</b></font></td>
  42.     <td>'.$book->PublisherText.'</td>
  43. </tr>';    
  44. }
  45.  
  46. $html .= '</table>';
  47.  
  48. echo $html;
  49.  
  50. ?>
  51.  
  52.  
Apr 6 '11 #1
0 1003

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Vincent Jones | last post by:
I have this piece of script and I'm trying to understand what the 'SET t.Z_ASSOC_ROW = (t.rowid - m.MinRowID) + 1' and the 'INNER JOIN' line is doing UPDATE t SET t.Z_ASSOC_ROW = (t.rowid -...
18
by: Scott Brady Drummonds | last post by:
Hi, everyeone, I recently stumbled on some code that someone else wrote that I don't like. However, I'm having trouble articulating what the bad quality of the following code is. The...
9
by: Eqbal | last post by:
I have been asked to include this piece of code on certain pages so people can track if a user is coming to that page after clicking a banner ad. I do not understand how this works. Anyone can...
2
by: N J | last post by:
Hi, I can't figure out how to put this into code, any help would be great..thanks. Basically, if counter is over 100 then show msgbox then close. If txt.Counter > 100 Then msgbox "my message"...
18
by: __PPS__ | last post by:
Hello, I'm a university student and I'm preparing for my final today. I'm reading course notes, I found completely strange piece of code. It makes me laugh, I think the teacher needs to prepare...
5
by: Raoul.Kamadjeu | last post by:
I want to dynamically create link to a text on an svg document. I've implemented this piece of code. Any idea why this doen't link to google.com? <svg> <script onload="init(evt)"> function...
2
by: srikar | last post by:
Hi can any one expalin me this piece of code In this code line is used for taking the input stream as line input stream. Please explain me Can I use getline() instead of line. When I am using the...
2
by: atlkhan | last post by:
Can someone please explain this php code. I would be grateful <?php // --------------- file tape2matlab2php.php // NOTE: if web-server and matlab server are NOT located on the same mashine...
2
by: YYweii | last post by:
Hi all my teacher say there is something wrong with this piece of code, but i can't figure it out, help ! void GetMemory(char *p, int num) { p = new char; }
7
by: AAaron123 | last post by:
I read the help on which says: The ClientScriptManager class is used to manage client-side scripts and add them to Web applications... But could use a little help. Can someone tell me what...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.