<?
//List all orders, and who has ordered - if any.
$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
right join
joins_orders 
on joins_orders.customer_id = joins_customers.customer_id",$db);
?>
<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 RIGHT JOIN returns all the rows from the second table (joins_orders), 
  even if there are no matches in the first table (joins_customers).
   If there had been any rows in joins_orders that did not have matches in joins_customers,
    those rows also would have been listed.
*/
?>
  </table>    