petenaylor Posted November 26, 2010 Share Posted November 26, 2010 Hi all I need to do a multiple if isset to get three variables from the URL. Here is my code for just one: if(isset($_GET['category'])) { $fetchproducts = mysql_query(" SELECT * FROM `products` WHERE category = '".$_GET['category']."'"); while($returnedProduct = mysql_fetch_array($fetchproducts)) { include('product-cell.php'); } How do I combine this to check what is the 'type' and 'colour' from the URL and fetch from the SQL accordingly? Many thanks for you help Pete Quote Link to comment Share on other sites More sharing options...
bugcoder Posted November 26, 2010 Share Posted November 26, 2010 i feel this solution is whats your requirement if(isset($_GET['category'])) { $condition = "category = ".$_GET['category']; }elseif(isset($_GET['color'])) { $condition = "color = ".$_GET['color']; }elseif(isset($_GET['type'])) { $condition = "type = ".$_GET['type']; } $fetchproducts = mysql_query(" SELECT * FROM `products` WHERE $condition"); while($returnedProduct = mysql_fetch_array($fetchproducts)) { include('product-cell.php'); } Quote Link to comment Share on other sites More sharing options...
petenaylor Posted November 26, 2010 Author Share Posted November 26, 2010 Thanks for you quick reply! Will that also work with multiple url parameters? So if the URL is: product.php?category=stone&type=sandstonepatiopaving&colour=lightgrey Can that ask the SQL to find products that have a category of stone and a type of sandstonepatiopaving and a colour of lightgrey Thanks Pete Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.