Skip to Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
346
Chapter 6
...at a glance
PHP
While you’ve been thinking about Katie’s JavaScript and HTML, her server-side guys
have been listening in. They’ve gone ahead and updated the getUpdatedSales.php script
to return the XML we’ve been talking about, complete with updated totals for board, boot,
and binding sales. Not too bad, huh? Here’s what the script looks like now:
<?php
// Connect to database
$conn = @mysql_connect(“mysql.headrstlabs.com”,
“secret”, “really-secret”);
if (!$conn)
die(“Error connecting to MySQL: ” . mysql_error());
if (!mysql_select_db(“headrst”, $conn))
die(“Error selecting Head First database: ” . mysql_error());
$select = ‘SELECT boardsSold, bootsSold, bindingsSold’;
$from = ‘ FROM boardsrus’;
$queryResult = @mysql_query($select . $from);
if (!$queryResult)
die(‘Error retrieving total boards sold from database.’);
while ($row = mysql_fetch_array($queryResult)) {
$boardsSold = $row[‘boardsSold’];
$bootsSold = $row[‘bootsSold’];
$bindingsSold = $row[‘bindingsSold’];
}
header(“Content-Type: text/xml”);
echo “<?xml version=\”1.0\” encoding=\”utf-8\”?>
?>
<totals>
<boards-sold><? echo $boardsSold; ?></boards-sold>
<boots-sold><? echo $bootsSold; ?></boots-sold>
<bindings-sold><? echo $bindingsSold; ?></bindings-sold>
</totals>
<? mysql_close($conn); ?>
The Boards ‘R’
Us database now
keeps up with three
products: boards,
boots, and bindings.
In this version of the app, we’r ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content