I am having trouble displaying the proper table info when query ==3 on this script I have customized. Can anyone tell me where the error is?
When I process query 1 and 2 everything works perfectly. but when I try query 3 the browser outputs the table columns for query 1 and 2, some of the data for query 3(not complete) and the table columns for query 3(taken from different mysql table).
I am thinking the bracketry on the first if statement is somehow wrong so it is picking up the first echo statements for the table columns when it shouldn't.
I am just starting so I am sure this is a cinch for some of you out there. Thanks for any help.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Iowa Lake Sales and Service New Mowers</title>
</head>
<body>
<?php
//database connection handle
$dbh=mysql_connect ('localhost', 'xxx', 'xxx') or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db (xxxxxxxxxx);
//Search for used riders-variable comes from index.php command line query
if (1 == $query){
$sql = 'SELECT FROM used_mowers WHERE cut BETWEEN 26 AND 99 ORDER BY price LIMIT 0, 30';
}
//search for used walks
if (2 == $query){
$sql = 'SELECT FROM used_mowers WHERE cut BETWEEN 18 AND 24 ORDER BY price LIMIT 0 , 30';
}
//misc search
if (3 == $query){
$sql = 'SELECT type,brand,model,size,price FROM other_equipment LIMIT 0 , 30';
}
$results = mysql_query($sql);
$rows = mysql_fetch_array($results);
if (mysql_num_rows($results) < 1){
echo "There are no units like this available at this time.";
exit;
}
//should display for riders or walks
if (1 | 2 == $query){
echo "<table border=1>\n";
echo "<tr>\n";
echo "<td>More Info</td><td>Year</td><td>Brand</td><td>Model</td><td>HP</td><td>Cut</td><td>Price</td>\n";
while ($rows = mysql_fetch_array($results)){
printf("<tr><td><a href=\"%s?id=%s\">%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",$PHP_SELF, $rows["id"],$rows["id"],$rows["year"],$rows["brand"],$rows["model"],$rows["hp"],$rows["cut"],$rows["price"]);
}//closes while statement
echo "</table>\n";
}//closes if statement
else {
echo "An error has occured. Sorry, no action can be taken.\n";
exit;
}
// should display for other equipment
if (3 == $query){
echo "<table border=1>\n";
echo "<tr>\n";
echo "<td>What</td><td>Brand</td><td>Model</td><td>Size</td><td>Price</td>\n";
while ($rows = mysql_fetch_array($results)){
printf("<tr><td>%s</td><td>%s</td><td><a href=\"%s?id=%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", $PHP_SELF, $rows["type"],$rows["brand"],$rows["model"],$rows["size"],$rows["price"]);
}
echo "</table>\n";
}
?>
</body>
</html>