Hey Folks I need a little help. I want to display rows from a table that have a certain value in their column. I know how to do this for just 1 and that's:
PHP Code:
$cat = $_GET['cat'];
if (empty($_GET['cat'])) { $query = "SELECT * FROM cat_ballpythons ORDER BY priority DESC"; }
else { $query = "SELECT * FROM cat_ballpythons WHERE cat1='$cat' ORDER BY priority DESC";}
$result = @mysql_query($query);
What I need to know is how to do it for more than 1 variable [like $cat2 and $cat3] and only if that variable is defined. For instance if none of the categories are defined it should display all items but if only 1 and 2 it should only what was chosen for categories #1 and #2. I attempted this with:
PHP Code:
$cat = $_GET['cat'];
$cat2 = $_GET['cat2'];
$cat3 = $_GET['cat3'];
if (empty($_GET['cat3'])) { $query = "SELECT * FROM cat_ballpythons WHERE cat1='$cat' AND cat2='$cat2' ORDER BY priority DESC"; }
elseif (empty($_GET['cat2'])) { $query = "SELECT * FROM cat_ballpythons WHERE cat1='$cat' ORDER BY priority DESC"; }
elseif (empty($_GET['cat'])) { $query = "SELECT * FROM cat_ballpythons ORDER BY priority DESC"; }
else { $query = "SELECT * FROM cat_ballpythons WHERE cat1='$cat' AND cat2='$cat2' AND cat2='$cat3' ORDER BY priority DESC"; }
But it doesn't work. I also need to know how to keep it from displaying the same tables over again if the variables are the same. Like say if Item #1 has "Stuff" in Cat1 and "Whatever" in Cat2 and "Nothing" in Cat3 I don't want it to be displayed 3 times if:
PHP Code:
page.php?cat1=stuff&cat2=whatever&cat3=nothing
The Overall goal needs to be that I need to be able to specify 3 variables from a table row and then echo the items that are equal to the query.