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
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.