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
https://forums.phpfreaks.com/topic/34605-trouble-_getting-value/
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 &&?

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.