Source of: ../Wda42/example.4-9.php

<?php
/*
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 &
Associates.
No warranty is attached; we cannot take responsibility for errors or fitness
for use.
*/
?>
<!DOCTYPE HTML PUBLIC 
               "-//W3C//DTD HTML 4.0 Transitional//EN"
               "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Hugh and Dave's Online Wines</title>
</head>
<body bgcolor="white">

<h1>New Wines</h1>
Here are three top new wines we have in stock
<br><br>
<?php
   
include 'db.inc';
   include 
'error.inc';
   
   
$query "SELECT wi.winery_name, 
                     i.cost,
                     i.case_cost,
                     w.year, 
                     w.wine_name, 
                     w.description 
             FROM wine w, winery wi, inventory i
             WHERE w.description != \"\"
             AND w.winery_id = wi.winery_id
             AND w.wine_id = i.wine_id
             ORDER BY i.date_added DESC LIMIT 3"
;

   
// Open a connection to the DBMS
   
if (!($connection = @ mysql_connect($hostName
                                       
$username
                                       
$password)))
      die(
"Could not connect to database");
      
   if (!
mysql_select_db("winestore"$connection))
      
showerror();


   
// Run the query created above on the database through
   // the connection
   
if (!($result = @ mysql_query ($query$connection)))
      
showerror();


   echo 
"\n<table border=\"0\">";

   
// Process the three new wines
   
while ($row = @ mysql_fetch_array($result))
   {
      
// Print a heading for the wine
      
echo "\n<tr>\n\t<td bgcolor=\"maroon\">" .
           
"<b><font color=\"white\">" 
           
$row["year"] . " " .
           
$row["winery_name"] . " " .
           
$row["wine_name"] . " " .
           
"</font></b></td>\n</tr>";

      
// Print the wine review
      
echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
           
"<b>Review: </b>" .
           
$row["description"] .
           
"</td>\n</tr>";

      
// Print the pricing information
      
echo "\n<tr>\n\t<td bgcolor=\"gray\">" .
           
"<b>Our price: </b>" 
           
$row["cost"] . 
           
"(" $row["case_cost"] . " a dozen)" .
           
"</td>\n</tr>";

      
// Blank row for presentation
      
echo "\n<tr>\n\t<td></td>\n</tr>";
   }

   echo 
"\n</table>\n";

   if (!
mysql_close($connection))
      
showerror();
?>
</body>
</html>


© 2000--2001 Hugh E. Williams and David Lane.
Valid HTML 4.01!