Jump to content


Photo

php switch control structure,SOLVED


  • Please log in to reply
9 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 07:43 AM

so i have this
<?php
switch($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;
}
?>
the first one works, but the last two dont, any suggestions...

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 20 October 2006 - 07:48 AM

It looks fine to me.. try printing out the values to double check:

print "hotelType: {$row_rsHotel['hotelType']}, Id: {$_GET['Id']}<br>";

Maybe the hoteltype matches but the Id doesn't?

#3 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 07:56 AM

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....

#4 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 10:15 AM

<?php
switch($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;
}
?>

i slightly changed it to this now, which is still not working

#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 20 October 2006 - 10:21 AM

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.

<?php

function 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']);
?>

Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 10:23 AM

i just meant this part is working fine

<?php
switch($row_rsHotel['hotelType'])
{
	case 'Hotel':
		if($row_rsPages['Id']== "15")
		include "pages/country.php";
		break;

but then after this it does not work

#7 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 10:31 AM

sorry for the double post, i seem to have found what id happening

if 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 ideas

and it does this if a change it to hotel, or villa aswell.....

#8 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 October 2006 - 10:33 AM

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...

<?php
switch($row_rsHotel['hotelType'])
{
	case 'Hotel':
		if($row_rsPages['Id']== "15")


Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#9 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 10:45 AM

i thought that when doing it, but how else could i change it

and also how come each of the hotels are effect by the first Hoteltype

#10 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 11:20 AM

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 ?????????????????




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users