Jump to content

Archived

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

ltoto

if statements and includes

Recommended Posts

what i want to do is i have an option in the SQl table called hotel type, where the type can either be hotel, villa or golf,

what i want it to do is

e.g

if the type = hotel , then show pages/hotel.php on Id=18

if type= villa, then show pages/villa.php on Id=19

if type=golf, then show pages/golf.php on Id=20

any suggestions.....

Share this post


Link to post
Share on other sites
Use the [url=http://php.net/control-structures.switch]switch[/url] control structure.

Share this post


Link to post
Share on other sites
and will that still switch between different Ids and pages though...

Share this post


Link to post
Share on other sites
maybe it would be easier to show u what i had written:

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

which obviously is wrong

Share this post


Link to post
Share on other sites
[code]<?php
switch($row_rsHotem['hotelType'])
{
case 'Hotel':
$row_rsPages['Id'] = 15;
include "pages/country.php";
break;
case default:
// default action
break;
}
?>[/code]

Share this post


Link to post
Share on other sites
it gives me this error

parse error, unexpected T_DEFAULT

from this

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

Share this post


Link to post
Share on other sites
It's not "case default", it's just "default".

Ken

Share this post


Link to post
Share on other sites
<?php
switch($row_rsHotel['hotelType'])
{
case 'Hotel':
if(@$_GET['Id']== "15")
include "pages/country.php";
break;
default:
// default action
break;
}
?>

i changed it to now and it works, i assumue i just do that for the other two bits

Share this post


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


default:
// default action
break;
}
?>


i tried this but it did not work..... any suggestions as to what i should do, i got no error

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.