Jump to content


Photo

SQL Linking table and Hidden Feilds


  • Please log in to reply
1 reply to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 19 October 2006 - 06:53 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?

#2 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 19 October 2006 - 08:33 AM

do i need to show the insert for the first code, the way I was gonna do this was with Hidden fields e.g

hidAction value =hotel

then do that for golf and villas...... if this makes sense




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users