Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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,'”
') 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
Category: ',catDesc,'
Price: ',recordPrice,'"; // 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$field> "; } $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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started