Jump to content


Photo

case switch help PLEASE!!!!!1


  • This topic is locked This topic is locked
2 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 24 October 2006 - 10:11 AM

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

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



and then it goes through to the hotels page, with this 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);
?>

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:

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

any suggestions please...

#2 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 24 October 2006 - 07:10 PM

anyone got ay advice....

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 24 October 2006 - 10:36 PM

I am experiencing deja vu with this post. Didn't I see this question here

http://www.phpfreaks....html#msg454976

Forum rules : Don't double post. Closed.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users