Jump to content

[SOLVED] Using ISSET to get to variables


kyleldi

Recommended Posts

Is it possible to use ISSET for two variables?  What i've got is a page that says if one url variable exists it does one thing, while if that previous variable and another exists, it does something else.  All I really know is that I can check for that variable with code such as

if isset($_GET['category'])){

but I'd like to get 'category' and 'sub'

 

I hope i'm making sense, :)

Link to comment
https://forums.phpfreaks.com/topic/153518-solved-using-isset-to-get-to-variables/
Share on other sites

if (isset ($var1))
{ //do something; }
elseif (isset($var1) && isset ($var2))
{ //do something else; }

 

&& = and

|| = or

 

you can simply use and or or in place of the symbols .. i've just always used the symbols (sorry, can't remember what they're called).

u can use a nested if statement or have an elseif

 

the elseif statement first

if isset($_GET['category']) && isset($_GET['subcategory'])){
   // blah blah
} elseif isset(_$GET['category']) {
  // blah blah
} else {
  // blah blah
}

 

Look as to why we have category and subcategory and understand why we have it above just plain category.

 

but in this instance, i wud prolly nest my ifs instead

if isset($_GET['category']))
  if(isset($_GET['subcategory'])){
     // blah blah
  } else {
    // blah blah
  }
} else {
  // blah blah
}

 

Have fun

 

 

Note that MrMarcus' code will fail the second if statement, as I stated its a pitfall, and never execute the 2nd if statement.

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.