13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

826 Chapter 33 Connecting to <strong>Web</strong> Services with XML <strong>and</strong> SOAP<br />

Finally, we come to the main event-h<strong>and</strong>ling loop. A summary of the possible actions<br />

is shown in Table 33.2.<br />

Table 33.2<br />

Action<br />

Possible Actions in the Main Event Loop<br />

Description<br />

browsenode<br />

detail<br />

image<br />

search<br />

addtocart<br />

deletefromcart<br />

emptycart<br />

showcart<br />

Shows books in the specified category.This is the default action.<br />

Shows the details of one particular book.<br />

Shows a large version of the book’s cover.<br />

Shows the results of a user search.<br />

Adds an item to the user’s shopping cart.<br />

Deletes an item from the shopping cart.<br />

Empties the shopping cart altogether.<br />

Shows the contents of the cart.<br />

As you can see, the first four actions in this table relate to retrieving <strong>and</strong> displaying information<br />

from Amazon.The second group of four deals with managing the shopping cart.<br />

The actions that retrieve data from Amazon all work in a similar way. Let’s consider<br />

retrieving data about books in a particular browsenode (category) as an example.<br />

Showing Books in a Category<br />

The code executed when the action is browsenode (view a category) is as follows:<br />

showCategories($mode);<br />

$category = getCategoryName($browseNode);<br />

if(!$category || ($category=='Best Selling Books')) {<br />

echo "Current Best Sellers";<br />

} else {<br />

echo "Current Best Sellers in ".$category."";<br />

}<br />

The showCategories() function displays the list of selected categories you see near the<br />

top of most of the pages.The getCategoryName() function returns the name of the current<br />

category given its browsenode number.The showBrowseNode() function displays a<br />

page of books in that category.<br />

Let’s begin by considering the showCategories() function.The code for this function<br />

is shown in Listing 33.5.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!