Hello! I'm having a slight problem with my code - i think it should be easy to solve but i'm still struggling to head around some php basics! My page kind of looks like this (although I've taken out a few hefty chunks that I don't think are relevant just to reduce the length of this post!):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<?php
include ("misc.php");
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
//Select all hotels from the chosen area
$query = "SELECT EstablishmentName,RoomsFrom,NumBedrooms,EstablishmentType,Address1,Address2,Town,County,DescriptionEnglish,LongDescriptionEnglish,Hotel_Id,Region,AARating,RACRating,AirportName,AirportHotel FROM hotel WHERE County='$County' OR Town='".$_GET['Town']."' OR (AirportName='".$_GET['AirportName']."' AND AirportHotel='Y') ORDER BY $sortBy LIMIT $offset, $limit";
$result = mysql_query($query)
or die ("Couldn't execute query");
//decide which stylesheet to include
switch ($Region)
{
case "Scotland" :
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheetscotland.css\">";
break;
case "Wales" :
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheetwales.css\">";
break;
default :
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheetengland.css\">";
break;
}
?>
</head>
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<?php
//to be used with language flags in header
$pagetitle = "showhotels";
//decide which header to include
switch ($Region)
{
case "Scotland" :
include ("headerscotland.php");
break;
case "Wales" :
include ("headerwales.php");
break;
default :
include ("header.php");
break;
}
?>
<table width="775" border="0" align="center" cellpadding="0" cellspacing="0" class="background">
<tr>
<td width="214" height="100%" valign="top">
<table width="214" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="214" valign="top" class="welcome">
<b>Welcome to Hotel Heaven!</b> <br><br><br><br></td>
</tr>
</table>
</td>
<td width="561">
<table width="561" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="537" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
<tr>
<td class="hotelsfound" colspan="2"><?php echo "Currently displaying results <b>" . $starting_no . "</b> to <b>" . $end_count . "</b> from a total of <b>" . $total . "</b> hotels."; ?></td>
</tr>
<tr>
<?php
if (isset($Town))
echo "<td class=\"sortby\"><a href=\"http://www.hotelheaven.co.uk/showhotels.php?Town=" . $Town . "&s=1\">Click here to view budget hotels first</a></td>";
if (isset($County))
echo "<td class=\"sortby\"><a href=\"http://www.hotelheaven.co.uk/showhotels.php?County=" . $County . "&s=1\">Click here to view budget hotels first</a></td>";
if (isset($AirportName) & $AirportHotel == "Y")
echo "<td class=\"sortby\"><a href=\"http://www.hotelheaven.co.uk/showhotels.php?AirportName=" . $AirportName . "&AirportHotel=Y&s=1\">Click here to view budget hotels first</a></td>";
if (isset($Town))
echo "<td class=\"sortby\" align=\"right\"><a href=\"http://www.hotelheaven.co.uk/showhotels.php?Town=" . $Town . "&s=2\">Click here to view luxury hotels first</a></td>";
if (isset($County))
echo "<td class=\"sortby\" align=\"right\"><a href=\"http://www.hotelheaven.co.uk/showhotels.php?County=" . $County . "&s=2\">Click here to view luxury hotels first</a></td>";
if (isset($AirportName) & $AirportHotel == "Y")
echo "<td class=\"sortby\" align=\"right\"><a href=\"http://www.hotelheaven.co.uk/showhotels.php?AirportName=" . $AirportName . "&AirportHotel=Y&s=2\">Click here to view luxury hotels first</a></td>";
?>
</tr>
</table>
</td>
</tr>
<tr>
<td class="lineheight" height="12"> </td>
</tr>
<tr>
<td>
<table width="537" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="ffffff">
<?php
//Display results in a table
while ( $row = mysql_fetch_array($result,MYSQL_ASSOC) )
{
//Do not remove - gets Region variable for use with next/previous buttons
$Region = $row['Region'];
?>
<tr>
<td colspan="2">
<table width="537" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="23" class="title"><a href="http://www.hotelheaven.co.uk/hotel.php?Hotel_Id=<?php echo $row['Hotel_Id'] ?>"><?php echo $row['EstablishmentName'] ?></a></td>
<td height="23" align="right" valign="middle" class="darkbackground">
<?php
for ( $i=0; $i < $row['AARating']; $i++ ) echo ("<img src=\"http://www.hotelheaven.co.uk/" . $row['Region'] . "/star.gif\">");
if ($row['AARating'] >= 1) echo ("<img src=\"http://www.hotelheaven.co.uk/" . $row['Region'] . "/AA.gif\">");
for ( $i=0; $i < $row['RACRating']; $i++ ) echo("<img src=\"http://www.hotelheaven.co.uk/" . $row['Region'] . "/star.gif\">");
if ($row['RACRating'] >= 1) echo ("<img src=\"http://www.hotelheaven.co.uk/" . $row['Region'] . "/RAC.gif\">");
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="contentleft" align="right">Rooms From</td>
<td class="content">£<?php echo $row['RoomsFrom'] ?></td>
</tr>
<tr class="lightbackground">
<td class="contentleft" align="right">Number of Rooms</td>
<td class="content"><?php echo $row['NumBedrooms'] ?> Bedroom <?php echo $row['EstablishmentType'] ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
My problem is with these bits:
//decide which stylesheet to include
switch ($Region)
{
case "Scotland" :
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheetscotland.css\">";
break;
case "Wales" :
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheetwales.css\">";
break;
default :
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheetengland.css\">";
break;
}
and...
switch ($Region)
{
case "Scotland" :
include ("headerscotland.php");
break;
case "Wales" :
include ("headerwales.php");
break;
default :
include ("header.php");
break;
}
I know I can't just write $Region as I need to call it first with something like...
$row = mysql_fetch_array($result)
and then I should use
$row['Region']
However, when i try and do this it sorts out my stylesheets and headers, but my while loop stops working! I'm guessing I can't use this same mysql_fetch_array line twice....but then how can I get the Region variable so I can use it before I've introduced the while loop??
Please help me! I'm going mad!
Lizzyd