Source code of dbSelectMult.php
<html>
<head>
<title>Select Across Tables</title>
</head>
<body>
<h2>Inventory</h2>
<table width='75%'>
<tr>
<th>Item Description</th>
<th>Color</th>
<th>Size</th>
<th>Quantity</th>
</tr>
<?php
$lines = file("mysql.txt");
$password = trim($lines[0]);
$dbLink = mysql_connect("localhost", "tboegel", $password)
or die("Can't connect: " . mysql_error());
mysql_select_db("clearwater", $dbLink)
or die("Can't select clearwater: " . mysql_error());
// In this example I am putting the query string in a variable,
// and then using that variable as an argument to mysql_query()
// Since this is a long string, I'm using the concatenation operator
// (the dot) to glue smaller strings together
// Pay particular attention to the spacing around the quotes
// For example, if I didn't have a space at the end of
// "FROM inventory, item "
// then the resulting query would look like:
// FROM inventory, itemWHERE ...
// and that would cause an error
$query = "SELECT item_desc, color, inv_size, inv_qoh "
. "FROM inventory, item "
. "WHERE inventory.item_id = item.item_id "
. "ORDER BY item_desc, color, inv_size";
$recordset = mysql_query($query, $dbLink)
or die("Problem with this query: $query -- the error message is " . mysql_error());
while ($row = mysql_fetch_assoc($recordset)) {
print "<tr>";
print "<td>{$row['item_desc']}</td>";
print "<td>{$row['color']}</td>";
print "<td>{$row['inv_size']}</td>";
print "<td>{$row['inv_qoh']}</td>";
print "</tr>\n";
}
mysql_free_result($recordset);
mysql_close($dbLink);
?>
</table>
</body>
</html>