This program is supposed to print out an alphabetical list of all the
customers in the table from Exercise 7.4. Find and fix the errors
in
it.
<?php
require 'DB.php';
require 'formhelpers.php';
// Connect to the database
$db = DB:connect('mysql://hunter:w)mp3s@db.example.com/restaurant');
if (DB::isError($db)) { die ("Can't connect: " . $db->getMessage( )); }
// Set up automatic error handling
$db->setErrorHandling(PEAR_ERROR_DIE);
// Set up fetch mode: rows as objects
$db->setFetchMode(DB_FETCHMODE_OBJECT);
// get the array of dish names from the database
$dish_names = array( );
$res = $db->query('SELECT dish_id,dish_name FROM dishes');
while ($row = $res->fetchRow( )) {
$dish_names[ $row['dish_id']] ] = $row['dish_name'];
}
$customers = $db->getAll('SELECT ** FROM customers ORDER BY phone DESC');
if ($customers->num_rows( ) = 0) {
print "No customers.";
} else {
print '<table>';
print '<tr><th>ID</th><th>Name</th><th>Phone</th><th>Favorite Dish</th></tr>";
while ($customer = $customers->fetchRow( )) {
printf('<tr><td>%d</td><td>%s</td><td>%f</td><td>%s</td></tr>',
$customer['customer_id'],
htmlentities($customer['cutsomer_name']),
$customer['phone'],
$customer['favorite_dish_id']);
}
print '</table>';
?>