Source code of dbFindAverageGood2.php

<html>
<head>
<title>Find Average Item Price</title>
</head>
<body>
<h2>Find Average Item Price</h2>

<?php
  $lines 
file("mysql.txt");
  
$password trim($lines[0]);
  
$dbLink mysql_connect("localhost""tboegel"$password);

  
mysql_select_db("clearwater"$dbLink);

  
$query "SELECT avg(inv_price) as average_price, cat_desc "
    
"FROM inventory, item, category "
    
"WHERE inventory.item_id = item.item_id "
    
"AND category.cat_id = item.cat_id "
    
"GROUP BY cat_desc";

  
$recordset mysql_query($query$dbLink);

  print 
"<table>";
  print 
"<tr><td>Category</td><td>Average Price</td></tr>";
  while(
$row mysql_fetch_assoc($recordset)) {
    print 
"<tr>";
    print 
"<td>{$row['cat_desc']}</td>";
    
printf("<td>\$%.2f</td>"$row['average_price']);
    print 
"</tr>";
  }
  print 
"</table>";

?>
</body>
</html>