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
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).

Link to comment
Share on other sites

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.

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.