Jump to content

Using if isset more than once


petenaylor

Recommended Posts

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

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');
}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.