For one of my projects I need to change what Categories and Sub Categories are selected in a Table depending on whether or not a Sub Category or difficulty is selected basically I need to do something like this:

$result = mysql_query(SELECT * FROM table WHERE category='$thecategory');

ok so that works so far but I need to be able to detect whether or not a Sub Category was selected which I do by passing a variable like Sub Category through the GET function.


$subCategory = $_GET['subcategory']

then I would like to update my SQL command like this but don't know how to properly:

$result = mysql_query(SELECT * FROM table WHERE category='$thecategory' if($subCategory){AND subCategory='$subCategory'});

I hope that makes sense, basically I need to detect if they've chosen a Sub Category and if they have only select things that are in the Main Category and the Sub Category. Thanks for any help.

Jordan Garn