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 Link to comment https://forums.phpfreaks.com/topic/219899-using-if-isset-more-than-once/ 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'); } Link to comment https://forums.phpfreaks.com/topic/219899-using-if-isset-more-than-once/#findComment-1139918 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 Link to comment https://forums.phpfreaks.com/topic/219899-using-if-isset-more-than-once/#findComment-1139922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.