boo_lolly Posted January 17, 2007 Share Posted January 17, 2007 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=85where 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] Quote Link to comment Share on other sites More sharing options...
Caesar Posted January 17, 2007 Share Posted January 17, 2007 http://www.mysite.com/index.php?cat=12&subcat=85Look at the above url....then look at yours...then test it again. ;) Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 17, 2007 Author Share Posted January 17, 2007 [quote author=Caesar link=topic=122843.msg507134#msg507134 date=1169061946]http://www.mysite.com/index.php?cat=12&subcat=85Look 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 &&? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.