trouble $_GETting value
Posted: Wed Jan 17, 2007 12:48 pm
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:
i guess my question is, why doesn't it work? and how do i check to see if subcat is there so can change $displayType for my switch() function?
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: Select all
<?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;
}
?>