Jump to content

trouble $_GETting value


boo_lolly

Recommended Posts

i have a shopping cart where the admin can enter items in categories, and even subcategories of existing categories. this subcategory value needs to be retrieved from the URL... ex  http://www.mysite.com/index.php?cat=12?subcat=85

where cat is the parent category, and subcat is the subcategory within category 12. i'm trying to write an if statement that will check to see if subcat is in the url, if it is... then do this, if not, do that... i thought i could use the $_GET[subcat] variable to do this, because it worked for my $_GET[cat] sql query. but it worked for $_GET[cat] when there was no subcat=? in the address bar... so i don't know what's going on or why it's not working. part of my code:
[code]
<?php
        if(isset($_GET[subcat])){
                $displayType = 3;
        }else{

      /*
        *check to see if there is a subcategory:
        *while loop checks for a match of the id#
        *(which is the same value as cat=? in the browser)
        *in the 'parent' column of the categories
        *table in the database. this cat id number is
        *retrieves from the browser using the $_GET[cat] variable
        *if there IS a match, then that category has
        *subcategories, hence set $displayType to some
        *matching # within the switch statement to display
        */
        $sql = mysql_query("SELECT * FROM categories");
        while($row = mysql_fetch_array($sql)){
                if($row[parent] == $_GET[cat]){
                        $displayType = 1;
                }
        }

      /*
        *if no subcategories were found
        *switch to display the items within
        *parent category
        */
        if($displayType != 1){
                $displayType = 2;
        }

  }//end else statemnet

        switch($displayType){
                case 1:
                          /*do something*/
                break;

                case 2:
                        /*do something else*/
                break;

                case 3:
                        /*do something completely different*/
                break;
      }
?>
[/code]
Link to comment
Share on other sites

[quote author=Caesar link=topic=122843.msg507134#msg507134 date=1169061946]
http://www.mysite.com/index.php?cat=12&subcat=85

Look at the above url....then look at yours...then test it again.  ;)
[/quote]
thanks caesar, that's what i thought the problem was... however, i've seen some use && instead of &. why would someone use two &&?
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.