Jump to content

Archived

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

ltoto

SQL and php help PLEASE!

Recommended Posts

right this is what i need to do, i have a hotel page, a golf page, and a villa page, when i click on the villa page it shows the list of villas, when i go on the hotel page, it shows the list of hotels, and when i go on the golf page it shows the list of golf hotels.


in the sql table i have a feild called hotelType, where in the backend they can select i f the hotel type is either Villa, Golf or Hotel

any suggestions as to how to do this please?

Share this post


Link to post
Share on other sites
On the hotel page:
"SELECT * FROM Hotel_Table WHERE hotelType='Hotel'"

On the villa page:
"SELECT * FROM Hotel_Table WHERE hotelType='Villa'"

On the Golf page:
"SELECT * FROM Hotel_Table WHERE hotelType='Golf'"

Orio.

Share this post


Link to post
Share on other sites
Itoto,

Am I to assume from this that you're starting again from scratch?  Trying to move away from your single index.php

Regards
Huggie

Share this post


Link to post
Share on other sites
well the customer has changed what they wanted

[code]?php
$colname_rsHotels = "1";
if (isset($_GET['hotelId'])) {
  $colname_rsHotels = (get_magic_quotes_gpc()) ? $_GET['hotelId'] : addslashes($_GET['hotelId']);
}
mysql_select_db($database_conTotal, $conTotal);
$query_rsHotels = sprintf("SELECT * FROM tabHotel WHERE hotelId = %s", $colname_rsHotels);
$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";
  }

echo "<div class=\"homebar2\"><h1>$name</h1></div>\n";
  echo "<div class=\"hotel\">$image</div>\n";
  echo "<div class=\"hotelcontent\">" .substr($description, 0, 300) . "...</div>\n";
  echo "<h3>Hotel Star: <img src=\"$star\" hspace=\"2\"></h3>\n";
echo "<div class=\"moreinfo\"><a href=\"index.php?Id=22&hotelId=$row[hotelId]\"><img src=\"../images/moreinfo.jpg\" alt=\"moreinfo\" width=\"75\" height=\"18\" border=\"0\"></a></div>\n";

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

so this is my code where the hotels are displayed, and this is used for the hotel, villa, and golf pages

Share this post


Link to post
Share on other sites
[code]<?php
mysql_select_db($database_conTotal, $conTotal);
$query_rsHotellist = "SELECT * FROM tabHotel WHERE hotelType = 'Hotel'";
$rsHotellist = mysql_query($query_rsHotellist, $conTotal) or die(mysql_error());
$row_rsHotellist = mysql_fetch_assoc($rsHotellist);
$totalRows_rsHotellist = mysql_num_rows($rsHotellist);

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

      echo <<<HTML
     
    <br>
<div class="homebar2"><h1>$name</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']}&hotelType={$row_rsHotellist['hotelType']}">{$row['regionName']}</a><br></div>
HTML;
}

mysql_free_result($rsHotellist);
?>
[/code]
this is the code to get to the hotels l ist aswell, but i have another page for villa, and golf, where I change the WHERE at the top to either golf of villa, and then at the bottom, change the Id to the right page

Share this post


Link to post
Share on other sites
at the moment, this is the link when you select the villa hotels

index.php?Id=20&id=1&hotelType=Villa

and with golf it will be

index.php?Id=19&id=1&hotelType=Golf

and with hotel:


index.php?Id=16&id=1&hotelType=Hotel

so on the page where all of these are displayed can i just put a get hoteltype from this part:

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

and how would i do this

any suggestions.....

Share this post


Link to post
Share on other sites
I'm going to be honest here.  I've helped a lot on one of the other posts with getting you up and running, but I can't help but feel the architecture of this site is all wrong.  For a start, the fact that you have a URL value called 'id' and another called 'Id' is very bad.

In this instance, what do 'Id' and 'id' represent, I obviously know what hotelType represents.

Regards
Huggie

Share this post


Link to post
Share on other sites
i no your right, but Im trying to get this bit working first, so then the site will be complete, then  iwill need to tidy this up, thanks for all the help you gave me in the past, this is the last bit that needs completing now, and then i can sort out all my bad coding, so if anyone could give me a hand, that would be great...

Id represents the page Id, and the small id represents the region id

Share this post


Link to post
Share on other sites
OK, that's fair enough.  Try this:

[code]<?php
mysql_select_db($database_conTotal, $conTotal);
$query_rsHotels = "SELECT * FROM tabHotel WHERE hotelType = {$_GET['hotelType']}";
$rsHotels = mysql_query($query_rsHotels, $conTotal) or die(mysql_error());
$row_rsHotels = mysql_fetch_assoc($rsHotels);
$totalRows_rsHotels = mysql_num_rows($rsHotels);
?>[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
thanks alot

i get thi error showing up

Unknown column 'Hotel' in 'where clause'

and obviously it changes for the golf and Villa pages

Share this post


Link to post
Share on other sites
That's saying that the column Hotel doesn't exist in your database.

Regards
Huggie

Share this post


Link to post
Share on other sites
well it is showing in the SQl table, they can choose which one they want in the Admin panel of the website, with a dropdown menu, this is the code for it

[code]<select name="selectType" id="selectType">
              <option value="Hotel" <?php if (!(strcmp("Hotel", $row_rsAccomedit['hotelType']))) {echo "SELECTED";} ?>>Hotel</option>
              <option value="Villa" <?php if (!(strcmp("Villa", $row_rsAccomedit['hotelType']))) {echo "SELECTED";} ?>>Villa</option>
              <option value="Golf" <?php if (!(strcmp("Golf", $row_rsAccomedit['hotelType']))) {echo "SELECTED";} ?>>Golf</option>

          </select>[/code]

Share this post


Link to post
Share on other sites
Yes, but the column in your database is called 'hotelType', not 'Hotel'.

Look at what the error message is telling you, somewhere in you're query, you have a WHERE clause looking for a column called 'Hotel', but it doesn't exist.  Check your WHERE clause columns.

Regards
Huggie

Share this post


Link to post
Share on other sites
well on the pages before i have something like this:

[code]<?php
mysql_select_db($database_conTotal, $conTotal);
$query_rsHotellist = "SELECT * FROM tabHotel WHERE hotelType = 'Hotel'";
$rsHotellist = mysql_query($query_rsHotellist, $conTotal) or die(mysql_error());
$row_rsHotellist = mysql_fetch_assoc($rsHotellist);
$totalRows_rsHotellist = mysql_num_rows($rsHotellist);[/code]

Share this post


Link to post
Share on other sites
ok, well I don't know then, are you using any dynamic column names, like this:

[code=php:0]SELECT * FROM tablename WHERE $column = '$value'
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
there all just like the one above
do you think it could be anything to do with this link


index.php?Id=16&id=1&hotelType=Hotel

when i take the hotel type bit off, it shows this error

Undefined index: hotelType

Share this post


Link to post
Share on other sites
or this makes the error go

index.php?Id=16&id=1&hotelType='Hotel'

i put ' ' around where it says hotel, but it again shows every hotel in every category, instrwad of separting them all

Share this post


Link to post
Share on other sites
sorry for triple post, but does anyone no which page this might be off, the error that is,

i have a page called page.php, which this is all included on, and 3 pages, called country.php, country_villa.php,country_golf.php, with the code that shows the country name and region names with thie country,

then the code for the hotel page which i just showed.....

Share this post


Link to post
Share on other sites
ok, its a new day, anyone have any ideas, when i changed the hoteltype part in the like with quotes around it it shows all of the hotels, so maybe its osmething to do with the link?

any ideas

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.