<?php
$tags = $_POST["search-tags"];
$age = $_POST["search-age"];
$rating = $_POST["search-rating"];
$city = $_POST["search-city"];
$state = $_POST["search-state"];
if (!$tags = "") { $tags = " WHERE `tags`='$tags'"; }
if (!$age = "") { $age = " WHERE `age`='$age'"; }
if (!$rating = "") { $rating = " WHERE `rating`='$rating'"; }
if (!$city = "") { $city = " WHERE `city`='$city'"; }
if (!$state = "") { $state = " WHERE `state`='$state'"; }
?>
This is all I got so far...
This is for a search page that displays the results in a table. I have all the other code I need but I'm having issues trying to ONLY include the search query variables that have data.
I would structure the query string like this:
$result = mysql_query( "SELECT * FROM `bgc_models` " . $tags . $age . $rating . $city . $state ) or trigger_error( mysql_error() );
But i then have the issue of how do I insert the "AND" where it's needed? I assume there has to be and easier way to do this. Any suggestions?