mediabob Posted July 17, 2007 Share Posted July 17, 2007 Hi, I am trying to get a URL parameter and use a case statement to insert a word based on the value of the parameter, but no matter what I do the value of the parameter always comes up as 1. My url is like this: http://mysite.com/test/example_page.php?example=3&catid=1 The second parameter, cat_id is the one I am having trouble with, I am using this code: if (isset($_GET['catid'])) { $catname = (get_magic_quotes_gpc()) ? $_GET['catid'] : addslashes($_GET['catid']); } switch ($catname) { case 0: $name = 'test1' && $section = "1"; break; case 1: $name = 'test2' && $section = "2"; break; //This is example there are more case statements . . . When doing this, the second part "$section" always comes up with the correct value but the first one, "$name" Always comes up as 1, I don't even know where this 1 is coming from Any help would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
mediabob Posted July 17, 2007 Author Share Posted July 17, 2007 I forgot to add, I did echo the value of $catname before it wen't through the switch statement and it does have the correct value, there just seems to be an issue with setting the value of $name btw wheres the edit button?? Quote Link to comment Share on other sites More sharing options...
tapos Posted July 17, 2007 Share Posted July 17, 2007 Can u explain the work of the following codes case 0: $name = 'test1' && $section = "1"; break; case 1: $name = 'test2' && $section = "2"; break; -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
mediabob Posted July 17, 2007 Author Share Posted July 17, 2007 Well, this is for a dynamic page that is going to be re-used, so name is the db table to querry and section is the column to compare with so you would have Select * From $name where $section = something This way it uses the correct table depending on where the user came from. Quote Link to comment Share on other sites More sharing options...
tapos Posted July 17, 2007 Share Posted July 17, 2007 case 0: $name = 'test1' && $section = "1"; break; You use logical and but use assignment oiperator, which is a logical error. You can try like this case 0: $name == 'test1' && $section == "1"; break; -- Tapos Pal 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.