Source code example for Web Database Applications
Unless otherwise stated, the source code distributed with this book can be
redistributed in source or binary form so long as an acknowledgment appears
in derived source files.
The citation should list that the code comes from Hugh E.
Williams and David Lane, "Web Database Application with PHP and MySQL"
published by O'Reilly & Associates.
This code is under copyright and cannot be included in any other book,
publication, or educational product without permission from O'Reilly &
No warranty is attached; we cannot take responsibility for errors or fitness
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
// Show the wines in an HTML <table>
echo "<h1>Our Wines</h1>\n";
// Start a table, with column headers
echo "\n<table>\n<tr>\n" .
"\n\t<th>Wine ID</th>" .
"\n\t<th>Wine Name</th>" .
"\n\t<th>Winery ID</th>" .
// Until there are no rows in the result set,
// fetch a row into the $row array and ...
while ($row = @ mysql_fetch_row($result))
// ... start a TABLE row ...
// ... and print out each of the attributes
// in that row as a separate TD (Table Data).
foreach($row as $data)
echo "\n\t<td> $data </td>";
// Finish the row
// Then, finish the table
$query = "SELECT * FROM wine";
// Connect to the MySQL server
if (!($connection = @ mysql_connect($hostName,
if (!(mysql_select_db($databaseName, $connection)))
// Run the query on the connection
if (!($result = @ mysql_query ($query, $connection)))
// Display the results
// Close the connection