Jump to content

case switch help PLEASE!!!!!1


ltoto

Recommended Posts

Ok So what i have at the moment is something where in the front end of the website it shows a coutry name, and a list of
regions within the country. e.g

Spain: Murica, Madrid

then when they click on the region the list of hotels appear within this region on a new page.

In the SQl i have 3 tables, 1 called Country, one called Region, and one called Hotels.

Country table:

id
countryName

Region Table

id
regionname
countryId ( this is picking up the id from the first table )

Hotels table

id
hotelname
hotelrating
countryname
regionId( picking the Id up from the region table )
hoteltype

and this is the code I have done this in in the front end

[code]<?php
if(@$_GET['Id']== "15") { ?>
<?php

$sql="SELECT c.countryName, c.countryImage, r.regionName, r.Id FROM tabCountry c, tabRegion r
WHERE c.Id = r.countryId";
$result = mysql_query($sql);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}
$country = "null";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  $cheader = $row['countryName'];
  if (strcmp($country,$cheader) !=0){
  $country = $row['countryName'];

  echo <<<HTML
 
<br>

 
<div class="homebar2"><h1>$cheader</h1></div>
<div class="country">  <img src="../thumb/phpThumb.php?src=../images/country_{$row['countryImage']}
&amp;w=100&amp;h=100&amp;zc=1" 
alt="Latest Deals">  </div> 

HTML;
  }
echo <<<HTML

<div class="countrycontent"><a href="index.php?Id=16&id={$row['Id']}">{$row['regionName']}</a><br></div>
HTML;
}
?>
<?php } ?>[/code]



and then it goes through to the hotels page, with this code ...

[code]<?php
mysql_select_db($database_conTotal, $conTotal);
$query_rsHotels = "SELECT * FROM tabHotel";
$rsHotels = mysql_query($query_rsHotels, $conTotal) or die(mysql_error());
$row_rsHotels = mysql_fetch_assoc($rsHotels);
$totalRows_rsHotels = mysql_num_rows($rsHotels);

$sql="SELECT * FROM tabHotel WHERE regionId = $id";
$result = mysql_query($sql);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  $name = $row['hotelName'];
  $description = $row['hotelDescription'];
  $rating = $row['hotelRating'];
  $image = "<img src=\"../thumb/phpThumb.php?src=../images/hotel_{$row['hotelImage']}&w=100&h=100&zc=1\" alt=\"Hotel\">"; 

if ($row['hotelRating'] == 3){
$star = "../images/star3.jpg";
}
else if ($row['hotelRating'] == 4){
$star = "../images/star4.jpg";
}
else if ($row['hotelRating'] == 5){
$star = "../images/star5.jpg";
}

// List the hotels
echo "<div class=\"homebar2\"><h1>".$name."</h1></div><div class=\"hotel\">".$image."</div><div class=\"hotelcontent\">".$description."</div><h3><img src=\"".$star."\" hspace=\"2\"></h3>
\n";
}

mysql_free_result($rsHotels);
?>[/code]

this is all working fine, for hotels

but now the client has asked that if this can be done for 3 different types:

Hotels ( which is done )
Golf
Villas

so I added the hoteltype to the hotels table in the SQL as you can see, and what I was thinking of is that, when
they are entering all this in the backend of the site, they ca nselect th hotel type, and it will go to that page
e.g if it is Villa then go to Id=19


any suggestions on how I can do this?

i tried using case, but all the records just follow the first hotelId, this si the coase code i used:

[code]switch($row_rsAccomodation['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:
 
  break;
 
}
?>[/code]

any suggestions please...
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

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.