402 CHAPTER 13 CASE STUDY: USING PHP (Apache web server for windows)

402 CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION The page then repeats the process for continents: else if (isset($continent)) { $sql = ‘SELECT * from continent WHERE continentID =’ . $continent; $tres = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($tres) == 0) { $current = $xml->createElement(‘current’, ‘Error’); $current = $root->appendChild($current); $error = $xml->createElement(‘error’, ‘You appear to have selected . an invalid continent’); $error = $root->appendChild($error); } else { $trow = mysql_fetch_array($tres); $continent_name = $trow['continent']; $sql = ‘SELECT * FROM country WHERE countryContinentID =’ . $continent . . ‘ ORDER BY country’; $cres = mysql_query($sql) or die(mysql_error()); $current = $xml->createElement(‘current’, $continent_name); $current->setAttribute(‘type’, ‘continent’); $current->setAttribute(‘id’, $continent); $root->appendChild($current); $items = $xml->createElement(‘items’); $root->appendChild($items); $linksto = $xml->createElement(‘linksto’, ‘country’); $items->appendChild($linksto); while ($crow = mysql_fetch_array($cres)) { $entry = $xml->createElement(‘entry’, $crow['country']); $entry->setAttribute(‘id’, $crow['countryID']); $items->appendChild($entry); } } } If none of the variables has been set, users are at the top level of navigation, and the application must display a list of continents from the database: else { $sql = ‘SELECT * FROM continent ORDER BY continent’; $cres = mysql_query($sql) or die(mysql_error()); $current = $xml->createElement(‘current’, ‘Home’); $current->setAttribute(‘type’, ‘home’); $root->appendChild($current); $items = $xml->createElement(‘items’); $root->appendChild($items); $linksto = $xml->createElement(‘linksto’, ‘continent’); $items->appendChild($linksto); while ($crow = mysql_fetch_array($cres)) {
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Web hosting uk – CHAPTER 13 CASE STUDY: USING PHP FOR

CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION 401 Finally, it loops through the results and creates a set of elements. Obviously, if there are no cities, it doesn t create any elements: while ($crow = mysql_fetch_array($cres)) { $entry = $xml->createElement(‘entry’, $crow['city']); $entry->setAttribute(‘id’, $crow['cityID']); $items->appendChild($entry); } Note that I ve left out the closing brackets to simplify the code. The code repeats this process for the country. This time, it returns the areas with the country as elements instead of the cities: else if (isset($country)) { $sql = ‘SELECT * from country WHERE countryID =’ . $country; $tres = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($tres) == 0) { $current = $xml->createElement(‘current’, ‘Error’); $current = $root->appendChild($current); $error = $xml->createElement(‘error’, ‘You appear to have selected . an invalid country’); $error = $root->appendChild($error); } else { $trow = mysql_fetch_array($tres); $country_name = $trow['country']; $sql = ‘SELECT * FROM area WHERE areaCountryID =’ . $country . ‘ . ORDER BY area’; $cres = mysql_query($sql) or die(mysql_error()); $current = $xml->createElement(‘current’, $country_name); $current->setAttribute(‘type’, ‘country’); $current->setAttribute(‘id’, $country); $root->appendChild($current); $items = $xml->createElement(‘items’); $root->appendChild($items); $linksto = $xml->createElement(‘linksto’, ‘area’); $items->appendChild($linksto); while ($crow = mysql_fetch_array($cres)) { $entry = $xml->createElement(‘entry’, $crow['area']); $entry->setAttribute(‘id’, $crow['areaID']); $items->appendChild($entry); } } }
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

400 CHAPTER 13 CASE STUDY: USING PHP (Web hosting account)

400 CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION The code then sets the document element using the createElement() and appendChild() methods: $root = $xml->createElement(‘entries’); $root = $xml->appendChild($root); The next code block tests which variable has been set: $area, $country, or $continent. It does this in an if/else statement that starts with the lowest navigation level, area: if (isset($area)) { If the $city variable is set, the code in standard.php will branch to include the mk_weather.php script instead. The code starts by retrieving the current area information from the database: $sql = ‘SELECT * from area WHERE areaID=’ . $area; $tres = mysql_query($sql) or die(mysql_error()); It also tests that the area id is valid: if (mysql_num_rows($tres) == 0) { $current = $xml->createElement(‘current’, ‘Error’); $current = $root->appendChild($current); $error = $xml->createElement(‘error’, ‘You appear to have selected . an invalid area’); $error = $root->appendChild($error); } If the query returns no rows, the application knows that the area id is invalid and the page can generate an element. If the query returns rows, the area name is stored in a variable for later use: else { $row = mysql_fetch_array($tres); $area_name = $row['area']; Once the page determines the area, it then needs to select the subnavigation city items: $sql = ‘SELECT * FROM city WHERE cityAreaID =’ . $area . ‘ ORDER BY city’; $cres = mysql_query($sql) or die(mysql_error()); The code can then use DOM methods to create the element and set the attributes: $current = $xml->createElement(‘current’, $area_name); $current->setAttribute(‘type’, ‘area’); $current->setAttribute(‘id’, $area); $root->appendChild($current); It also creates the and elements: $items = $xml->createElement(‘items’); $root->appendChild($items); $linksto = $xml->createElement(‘linksto’, ‘city’); $items->appendChild($linksto);
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Yahoo free web hosting – CHAPTER 13 CASE STUDY: USING PHP FOR

CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION 399 If users change the URL to http://localhost/weather/index.php?continent=7643, one of two things can happen. Either the value 7643 refers to a continent in the database, or the id is invalid. In the first case, the application can display the subnavigation for that continent, but in the second case, it needs to display an error message. The application uses the following XML document structure for this scenario: Error You appear to have selected an invalid continent Instead of an element, the document includes Error as the value of the element. It also includes an element with an error message that displays to the user. Scenario 3: Dealing with Subnavigation Items The most likely scenario is that the application displays subnavigation items. The structure of this type of XML document is similar to that shown in scenario 1. The difference is that the element contains multiple elements: WA city Albany Bunbury Geraldton Perth Each element has an idthat corresponds to the idfield in the database. It also contains the name of the navigation item in this case, the name of the city. Now let s see how to build the XML document to cope with these different scenarios. Building the XML Document The mk_navxml.php document starts by including weather.php: xmlStandalone = false;
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

398 CHAPTER 13 CASE (Apache web server for windows) STUDY: USING PHP

398 CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION The application uses the following template for the XML document built from the database content: The document element is . The element specifies the user s current position in the navigation system. The element contains a element. This element specifies the links from this level. The element also contains a list of elements, one for each navigation item at this level. An XSLT stylesheet uses the values in the elements to create the links to the subsequent levels of navigation. The structure of the XML document built by the application needs to take into account the following scenarios: 1. There are no subnavigation items to display. 2. The values in the querystring change and cause an error. 3. There are subnavigation items to display. The last scenario is the most likely, but I ll look at the XML structure that the application needs to produce for each option. Scenario 1: No Subnavigation Items The first situation I ll look at is where the users have reached a point in the navigation where there are no subnavigation items. A sample XML file structure for this scenario follows: WA city In this structure, I ve navigated to Western Australia (WA), a state in Australia. The element shows that I m in an areacalled WA. However, the element doesn t contain tags, as no cities are specified within the area. Scenario 2: Changing Querystring Variables Users might change the values in the querystring, perhaps changing one of the variables to see what happens. Let s assume that the URL to generate the XML document in scenario 1 was http://localhost/weather/index.php?continent=1.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

CHAPTER 13 CASE STUDY: USING PHP (Web hosting comparison) FOR

CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION 397 Let s work through the code in a little more detail. First, the page creates two DomDocument objects for the XML and XSL documents: $xsl = new DomDocument(); $inputdom = new DomDocument(); Then it tests to see if the $city variable is set and includes the appropriate document. The code also loads the related XSLT stylesheet: if (isset($city)) { include ‘mk_weather.php’; $xsl->load(‘weather.xsl’); } else { include ‘mk_navxml.php’; $xsl->load(‘nav.xsl’); } The next code block loads the XML content and creates a new XsltProcessor: $xml->loadXML($xml->saveXML()); $proc = new XsltProcessor(); The code then imports the stylesheet and applies the transformation, displaying the output in the page: $xsl = $proc->importStylesheet($xsl); $newdom = $proc->transformToDoc($xml); echo $newdom->saveXML(); mk_navxml.php The mk_navxml.php script is a complicated page responsible for much of the work in the application. This page creates the XML document that the application uses for the navigation in the site. The variables passed to the page determine the navigation system. There are four types of navigation to display: 1. The $area variable is set, so the navigation should display the cities. 2. The $country variable is set, so the navigation should display the areas. 3. The $continent variable is set, so the navigation should display the countries. 4. No variables are set, so the navigation should display a list of continents.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

396 CHAPTER 13 (Bulletproof web design) CASE STUDY: USING PHP

396 CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION standard.php The standard.php page determines what content to display on the page. If the page has set the $city variable, the users have chosen a city and wish to see the weather. Figure 13-10 shows the content that displays when the $city variable is set but when there are no weather entries. Figure 13-10. Displaying city details where no weather is entered If the $city variable hasn t been set, the page needs to display further navigation so users can navigate to the city level. The standard.php page follows: load(‘weather.xsl’); } else { include ‘mk_navxml.php’; $xsl->load(‘nav.xsl’); } $xml->loadXML($xml->saveXML()); $proc = new XsltProcessor(); $xsl = $proc->importStylesheet($xsl); $xml = $proc->transformToDoc($xml); echo $newdom->saveXML(); ?>
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

CHAPTER 13 CASE STUDY: USING PHP FOR (Http web server)

CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION 395 The SELECT statement determines the country. If the database contains a valid country, the page provides a link. The application uses the same approach for the area level, where it provides links back to the area s country and continent: if (isset($area)) { $sql = ‘SELECT area.areaCountryID, country.*, continent.* . FROM area, country, continent WHERE areaCountryID=countryID . AND countryContinentID=continentID AND areaID=’ . $area; $cRes = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($cRes) == 1) { $cRow = mysql_fetch_array($cRes); echo ‘‘ . . $cRow['continent'] . ‘
‘; echo ‘‘ . . $cRow['country'] . ‘
‘; } } Finally, when users are at a city level, they need to be able to link back to the area, country, and continent: if (isset($city)) { $sql = ‘SELECT city.cityAreaID, area.*, country.*, continent.* . FROM city, area, country, continent WHERE cityAreaID=areaID . AND areaCountryID=countryID AND countryContinentID=continentID . AND cityID=’ . $city; $cRes = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($cRes) == 1) { $cRow = mysql_fetch_array($cRes); echo ‘‘ . . $cRow['continent'] . ‘
‘; echo ‘‘ . . $cRow['country'] . ‘
‘; echo ‘‘ . . $cRow['area'] . ‘
‘; } } ?> You ll notice that the SQL statements become more complicated as the page determines more levels in the navigation hierarchy.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Web hosting compare – 394 CHAPTER 13 CASE STUDY: USING PHP

394 CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION sidebar.php The sidebar.php script builds the breadcrumb navigation for the left of the index.php page. Figure 13-9 shows the navigation system. Notice that I ve used Australasia in the example, which isn t, strictly speaking, a continent. Figure 13-9. The index.php page showing the breadcrumb navigation The sidebar.php page starts with a link to the home page: Home
The page needs to connect to the database, so it must include the weather.php file: ‘ . . $cRow['continent'] . ‘
‘; } }
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

CHAPTER 13 CASE STUDY: USING PHP FOR (Make web site)

CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION 393 This code sets up the page, links to an external stylesheet, and embeds some stylesheet declarations associated with the ids of

elements. The section of the page contains a series of
elements. The first, layHeading, contains the heading image:
Page Heading

The second, layNavigation, contains the navigation on the left side of the screen. The navigation comes from the page sidebar.php, which I ll look at shortly:

The final

element encloses the content from the page, which comes from standard.php:

The standard.php page determines whether to display additional levels of navigation either countries, areas, or cities. If users select a city, this page displays the weather conditions. I ll work through the page shortly. standard.css The CSS stylesheet standard.css provides formatting for index.php. It contains a set of standard declarations for elements on the page: body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #000000; } strong { font-size: 12px; font-weight: bold; } a { color : #0066FF; text-decoration : none; } a:hover, a:active { text-decoration : underline; }
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.