I have a table called new_cars with the columns model, make, & price.
I have a form that allows the user to select the model, make, and/or price (enter maximum amount). The form then calls on another script which I listed in the previous post. I am just trying to search the new_cars table based on the data they put in the form and display the results. It works when they enter just one item, but when they enter two or all three items, it comes back with no data. It doesn't error out, it just comes back with no data.
On your example, I commented out my code & pasted your code, but it gives me a parse error. I am a bit of a newbie, so I truly appreciate your help. Below is the code of the whole script.
<?
$dbuser = '**';
$dbhost = '';
$dbpass = '';
$dbname = '**';
$dbtble = 'new_cars';
$mysql_link = mysql_connect($dbhost,$dbuser,$dbpass);
$column = mysql_list_fields($dbname,$dbtble,$mysql_link);
/
if ($Make=='')
$sql = "SELECT from new_cars where model = '$Model' and price
< '$Price' + 0";
else if ($Model=='')
$sql = "SELECT * from new_cars where make = '$Make' and price
< '$Price' + 0";
else if ($Price=='') {
$sql = "SELECT * from new_cars where make = '$Make' and model =
'$Model'";
}
else if (($Make=='') & ($Model==''))
$sql = "SELECT * from new_cars where price < '$Price' + 0";
else if (($Make=='') & ($Price==''))
$sql = "SELECT * from new_cars where model = '$Model'";
else if (($Price=='') & ($Model==''))
$sql = "SELECT * from new_cars where make = '$Make'";
else if (($Make!=='') & ($Model!=='') & ($Price!==''))
$sql = "SELECT * from new_cars where make = '$Make' and
model = '$Model' and price < '$Price' + 0";
else if (($Make=='') & ($Model=='') & ($Price==''))
$sql = "SELECT * from new_cars";
else
print "There was an erro";
$result = mysql_db_query($dbname,$sql);
if ($result=='')
echo "No rows.";
*/
function set_condition( $result, $column, $value, $operator, $sep )
{
if ($value != '') // if arg is blank, don't do anything at all to the query string
{
if ($result == '') // first condition being added to query
$result = ' where ';
else
$result .= ' and ';
$result .= "$column $operator $sep$value$sep";
}
return $result
}
$sql = 'SELECT * from new_cars ';
$where = set_condition( $where, 'model', $Model, '=', "'");
$where = set_condition( $where, 'make', $Make, '=', "'");
$where = set_condition( $where, 'price', $Price, '<', '');
echo "query = $sql";
?>
<table bgcolor="black">
<tr><td>
<table><!---- Inside Table ---->
<?
while($value = mysql_fetch_array($result))
{
print "<tr BGCOLOR=YELLOW>";
//This loop goes through the colums and prints
//each value
for($i=0; $i< mysql_num_fields($column); $i++ )
{
print "<td> $value[$i] </td>";
}
print "</tr>";
}
mysql_free_result($result);
mysql_close();
?>
</table><!---- Inside Table ----->
</td></tr>
</table>