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.

Leave a Reply