I need to use this code :
<?php
// include the file for the database connection
include_once("database_conn.php");
// if useXML was sent as part of the url then
if (isset( $_REQUEST['useXML'] )) {
// echo whatever getXMLOffer returns to the browser or back to the ajax script
echo getXMLOffer();
} else { // otherwise just an html record is required
// so echo whatever getHTMLOffer returns to the browser or back to the ajax script
echo getHTMLOffer();
}
function getHTMLOffer() {
// store the sql for a random special offer, the sql wraps things using concat in an html 'wrapper'
$sql2 = "select concat('<p>“',bookTitle,'”<br />\n<span class=\"category\">Category: ',catDesc,'</span><br />\n<span class=\"price\">Price: ',bookPrice,'</span></p>') as offer from nbc_book_special_offers inner join nbc_category on nbc_book_special_offers.catID = nbc_category.catID order by rand() limit 1";
// execute the query
$rsOffer = mysql_query( $sql2 );
// get the one quotation returned
$offer = mysql_fetch_assoc($rsOffer);
// return the quote
return $offer['offer'];
}
function getXMLOffer() {
$sql = "select bookTitle, catDesc, bookPrice from nbc_book_special_offers inner join nbc_category on nbc_book_special_offers.catID = nbc_category.catID order by rand() limit 1";
$xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
$rsOffer = mysql_query( $sql );
// start to assemble an output string with the xml head and root element
$output = $xmlHeader;
$output .= "<root>\n";
while ( $record = mysql_fetch_assoc( $rsOffer ) ) {
// start a new record element in xml and add to the output
$output .= "\t<offer>\n";
// 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>\n";
}
$output .= "\t</offer>\n";
}
$output .= "</root>";
return $output;
}
?>
to print the xml created which looks like:
<?xml version="1.0" encoding="UTF-8" ?> <root> <offer> <bookTitle>Actionscript with PHP</bookTitle> <catDesc>Flex & Flash Programming</catDesc> <bookPrice>15.00</bookPrice> </offer> </root>
but it needs to refresh every 5 seconds can anybody help me

New Topic/Question
Reply


MultiQuote




|