Jump to content

Archived

This topic is now archived and is closed to further replies.

ltoto

php switch control structure,SOLVED

Recommended Posts

so i have this
[code]
<?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;
}
?>
[/code]
the first one works, but the last two dont, any suggestions...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites
[code]<?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;
}
?>[/code]

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

Share this post


Link to post
Share on other sites
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]
<?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']);
?>
[/code]

Good Luck,
Tom

Share this post


Link to post
Share on other sites
i just meant this part is working fine

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

but then after this it does not work

Share this post


Link to post
Share on other sites
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.....

Share this post


Link to post
Share on other sites
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]<?php
switch($row_rsHotel['hotelType'])
{
case 'Hotel':
if($row_rsPages['Id']== "15")
[/code]
[/quote]

Regards
Huggie

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 ?????????????????

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.