ltoto Posted October 20, 2006 Share Posted October 20, 2006 so i have this[code]<?phpswitch($row_rsHotel['hotelType']){ case 'Hotel': if(@$_GET['Id']== "15") include "pages/country.php"; break; case 'Villa': if(@$_GET['Id']== "3") include "pages/country.php"; break; case 'Golf': if(@$_GET['Id']== "2") include "pages/country.php"; break; default: // default action break;}?>[/code]the first one works, but the last two dont, any suggestions... Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/ Share on other sites More sharing options...
btherl Posted October 20, 2006 Share Posted October 20, 2006 It looks fine to me.. try printing out the values to double check:[code]print "hotelType: {$row_rsHotel['hotelType']}, Id: {$_GET['Id']}<br>";[/code]Maybe the hoteltype matches but the Id doesn't? Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111714 Share on other sites More sharing options...
ltoto Posted October 20, 2006 Author Share Posted October 20, 2006 they seem to show up fine on every page , hmmmmmmm.....something must be wrong with the if parts in the code then, but i am not sure what.... Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111717 Share on other sites More sharing options...
ltoto Posted October 20, 2006 Author Share Posted October 20, 2006 [code]<?phpswitch($row_rsHotel['hotelType']){ case 'Hotel': if($row_rsPages['Id']== "15") include "pages/country.php"; break; case 'Villa': if($row_rsPages['Id']== "3") include "pages/country_villa.php"; break; case 'Golf': if($row_rsPages['Id']== "2") include "pages/country_golf.php"; break; default: // default action break;}?>[/code]i slightly changed it to this now, which is still not working Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111750 Share on other sites More sharing options...
tomfmason Posted October 20, 2006 Share Posted October 20, 2006 You said that the first one was working correctly right?Please post the method that you come up with the $row_rsHotel['hotelType']Now this is how I like to use the switch statement.[code]<?phpfunction getPage($page) { switch($page) { case "something": //some code here break; case "something_else": //some more code here break; default: //something else break; }}getPage($row_rsHotel['hotelType']);?>[/code]Good Luck,Tom Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111755 Share on other sites More sharing options...
ltoto Posted October 20, 2006 Author Share Posted October 20, 2006 i just meant this part is working fine [code]<?phpswitch($row_rsHotel['hotelType']){ case 'Hotel': if($row_rsPages['Id']== "15") include "pages/country.php"; break;[/code]but then after this it does not work Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111759 Share on other sites More sharing options...
ltoto Posted October 20, 2006 Author Share Posted October 20, 2006 sorry for the double post, i seem to have found what id happeningif I change the hotel type on the first hotel e.g :If Id=1 and the type is golf, it will take everything onto the golf pages, e.g all other ideasand it does this if a change it to hotel, or villa aswell..... Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111761 Share on other sites More sharing options...
HuggieBear Posted October 20, 2006 Share Posted October 20, 2006 I may have something wrong here, but I always thought that the 'switch' statement was an alternative way of writing 'if' statements? If this is a case, then why combine both in the same piece of code...[quote author=ltoto link=topic=112094.msg454870#msg454870 date=1161339827][code]<?phpswitch($row_rsHotel['hotelType']){ case 'Hotel': if($row_rsPages['Id']== "15")[/code][/quote]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111764 Share on other sites More sharing options...
ltoto Posted October 20, 2006 Author Share Posted October 20, 2006 i thought that when doing it, but how else could i change itand also how come each of the hotels are effect by the first Hoteltype Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111768 Share on other sites More sharing options...
ltoto Posted October 20, 2006 Author Share Posted October 20, 2006 what about if i just use if statements instead, although, this does seem to be working, just everything moves with the hotel type of the first Id, so would it be anything to do with the included page it goes to, or not ????????????????? Quote Link to comment https://forums.phpfreaks.com/topic/24518-php-switch-control-structuresolved/#findComment-111781 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.