Question: Given the following PHP code: ; // Start to assemble an output string with the xml head and root element $output = $xmlHeader; $output .=

Given the following PHP code:

getMessage(), 0, $e); } if (isset($_REQUEST['useXML'])) { // echo what getXMLOffer returns echo getXMLOffer($dbConn); } else { // otherwise just an html record is required // so echo whatever getHTMLOffer returns to the browser or back to the ajax script echo getHTMLOffer($dbConn); } function getHTMLOffer($dbConn) { try { // store the sql for a random special offer, the sql wraps things using concat in an html 'wrapper' $sql = "select concat('

“',recordTitle,'”
Category: ',catDesc,'
Price: ',recordPrice,'

') as offer from nmc_special_offers inner join nmc_category on nmc_special_offers.catID = nmc_category.catID order by rand() limit 1"; // execute the query $rsOffer = $dbConn->query($sql); // get the one offer returned $offer = $rsOffer->fetchObject(); // return the offer return $offer->offer; } catch (Exception $e) { return "Problem: " . $e->getMessage(); } } function getXMLOffer($dbConn) { try { $xmlHeader = " "; // Start to assemble an output string with the xml head and root element $output = $xmlHeader; $output .= " "; $sql = "select recordTitle, catDesc, recordPrice from nmc_special_offers inner join nmc_category on nmc_special_offers.catID = nmc_category.catID order by rand() limit 1"; $rsOffer = $dbConn->query($sql); while ( $record = $rsOffer->fetchObject() ) { // start a new record element in xml and add to the output $output .= "\t "; // iterate through each record pulling out the fieldname and its value foreach ( $record as $field => $value ) { $value = htmlspecialchars( $value ); // wrap up the fields and values as xml $output .= "\t\t<$field>$value "; } $output .= "\t "; } $output .= ""; return $output; } catch (Exception $e) { return "Problem: " . $e->getMessage(); } } ?>

How would I retrieve an XMLOffer using this file in a similar way to how the following script uses the getHTMLOffer() function, so that the page updates every 5 seconds? Could you also provide comments to help me to understand what is being done:

 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!