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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.