<?
//List all customers, and their orders - if any using the left join
$db = mysql_connect("localhost", "mmaaaco_ksecor", "hamilton");
mysql_select_db("mmaaaco_mydb",$db);
$result = mysql_query("select joins_customers.name, joins_orders.product
from joins_customers
left join
joins_orders 
on joins_orders.customer_id = joins_customers.customer_id",$db);
if (!$result) echo mysql_error();
?>
<table>
	<tr><td colspan="4"><a name="top"><h3>Student Practice Queries</h3></a>
</td>
	</tr>
	<tr>
	<th align="left">Name</th>
	<th align="left" >Product</th>
	</tr>
 <? 
 // display list if there are records to display. The %s is a placeholder for each field you select below
 	if ($myrow = @mysql_fetch_array($result)) {

      

      do {

        printf("<tr><td>%s</td><td>%s</td></tr>\n",
         $myrow["name"], $myrow["product"]);

      } 
      while ($myrow = mysql_fetch_array($result));
  }
  /* The LEFT JOIN returns all the rows from the first table (joins_customers), 
  even if there are no matches in the second table (joins_orders). 
  If there are rows in Employees that do not have matches in Orders, those rows also will be listed.
  */
  ?>
  </table>    