The code:

$selecteddate = $_POST['Releasedate'];
$selectedplatform =$_POST['Platform'];
$selectedstyle = $_POST['style'];
$query="SELECT * FROM $table WHERE date = '$selecteddate'AND Style = '$selectedstyle'AND Platform = '$selectedplatform'";

Ok, the code works if someone picks something for all 3 of the items, so all of the code works, but if someone leaves one of the $selected items blank I have it returning a *, which doesn't mean what I thought it would mean. So what should I have it return so that if they do not choose an option I want it to just ignore that part of the WHERE condition?

$selecteddate = $_POST['Releasedate'];
$selectedplatform =$_POST['Platform'];
$selectedstyle = $_POST['style'];

$whereclause = "";
if ($selecteddate!="*") $whereclause.= " AND date='$selecteddate' ";
if ($selectedplatform!="*") $whereclause.= " AND Platform='$selectedplatform' ";
if ($selectedstyle!="*") $whereclause.= " AND Style='$selectedstyle' ";

if (strlen($whereclause) > 0) $whereclause = " WHERE ".substr($whereclause,4);

$query="SELECT * FROM $table $whereclause";

If you change your form to return "" instead of "*" on blank inputs, just remove the * in lines 6,7,8

Thanks very much for your help, worked perfectly.

You can also make javascript validation along with the Server Side Validation on the form in order to post/get the correct values.

I hope the above solution did help.

Thanks,

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.