Jump to content


Photo

Linking to Specific Id's


  • Please log in to reply
33 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 03:28 PM

Couldnt think of the right title for this, anyway...

So i what i have done already is i have a table like this:

tabCountry - countryId, countryName
tabRegion - Id, countryId, regionName
tabHotel - Id, regionId, hotelName, hotelImage, hotelDescription, hotelRating

so what i am doing is a system like the example on this website:
http://212.161.124.21/hotellist.asp

i have the countrys and regions bit working, so there is the countrys listed, and within the countrys there is the list of region withineach country, i used the code below

<?php

$sql="SELECT c.countryName, 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 (is_null($country) || strcmp($country,$cheader) !=0){
      $country = $row['countryName'];	
      echo <<<HTML
        <br>
         <h2>$country</h2>
HTML;
   }
echo <<<HTML
   <a href="../pages/hotels.php?Id=$row[Id]">$row[regionName]</a><br>
HTML;
}
?>

so when you click on a region, it goes to a new page with the list of hotels from that region, so I am now looking how a link the hotels to the region so that when the click on the region, just the hotels from that region appear, and not all the hotels, hope this makes sense....

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 03:59 PM

hotels.php needs the following:

<?php
$id = $_GET['Id'];

$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'];
   // List the hotels
   echo "$name - $rating - $description<br>\n"
}

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 04:27 PM

$id = $_GET['Id'];

this is the bit that is not working now, i did change $id to $Id aswell which didnt seem to work

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 04:57 PM

If you right click on the page that has the list of countries and regions and then view the source.  Does the <a href... link look correct?

Does it say something like
<a href="../pages/hotels.php?id=5">Greece</a>

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 05:07 PM

/pages/hotels.php?Id=1

annd the id changes with each one to the correct id

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 05:10 PM

OK, so we know it's getting the right id...

So on your hotel.php, if you type this:

<?php
   $id = $_GET['Id'];
   echo $id;
?>

Does it echo the correct values... Try clicking a couple of regions from the previous page.

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 05:24 PM

ok i will have to get back to you tommorrow, because it is now hometime, thanks for all the help today though

#8 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 05:29 PM

No problem, my pleasure.

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#9 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 07:55 AM

ok, so it does echo the correct values

#10 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 15 September 2006 - 08:01 AM

it sounds like perhaps what you need then is to do a sql join where you join the hotels to the region so that it will pull only hotels from that region and spit them out to you in a results array....

#11 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 08:20 AM

ahhhh i seem to of gotten it working now, thanks for the help

#12 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 15 September 2006 - 08:21 AM

What was it Itoto?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#13 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 08:27 AM

its stopped working again now, basically, when i make hotels as a separte page, its fine, but when it is as an includes and i take the connection of the top it does not work.

Also a quick question, what include would i put on the index page for the hotels page

i would use this normally because iput most things in one page

<?php  include 'pages/page.php'; ?>
, but obviously i just want it to appear when they click on the region name

#14 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 08:55 AM

Right this is the code at the moment
<?php
mysql_select_db($database_conTotal, $conTotal);
$query_rsHotel = "SELECT * FROM tabHotel";
$rsHotel = mysql_query($query_rsHotel, $conTotal) or die(mysql_error());
$row_rsHotel = mysql_fetch_assoc($rsHotel);
$totalRows_rsHotel = mysql_num_rows($rsHotel);

$id = $_GET['Id'];

$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'];
   // List the hotels
   echo "$name - $rating - $description<br>\n";
}
?>
<?php
mysql_free_result($rsHotel);
?>

which brings Undefined Variable errors, so Im assuming this means i have done something wrong with the include on the index page



#15 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 15 September 2006 - 09:15 AM

OK, still have this code on the index.php (note, I've changed the link at the bottom of the page to call the current page.

<?php

$sql="SELECT c.countryName, 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 (is_null($country) || strcmp($country,$cheader) !=0){
      $country = $row['countryName'];	
      echo <<<HTML
        <br>
         <h2>$country</h2>
HTML;
   }
echo <<<HTML
   <a href="{$_SERVER['PHP_SELF']}?id={$row['Id']}">{$row['regionName']}</a><br>
HTML;
}
?>

Then where you want your list of hotels to appear on your index.php page, have this:

if (isset($_GET['id']){
   $id = $_GET['id'];
   include('hotel.php');
}

and your hotel.php looks like this:

<?php
$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'];
   // List the hotels
   echo "$name - $rating - $description<br>\n";
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#16 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 09:21 AM

i forgot to explain something sorry, on the index page, there is an include to pages page like this

<?php  include 'pages/page.php'; ?>

and on the "page" page, that is where all the functions are which i have shown you before, like the list of hotels and countrys, and page content.

so Im assuming i would need to do something on the index page where,

i put the hotels include on that page, but some how say, only show pages/hotels.php, if the region name is clicked on, on pages/page.php


does that make any sense?

#17 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 15 September 2006 - 09:32 AM

It does, but I think you're getting slightly confused.  Once a page is 'included' it becomes part of the page it's being included in.

if I have index.php like this:

<?php
include('header.php');
echo <<<HTML;
 <body>
 </body>
<html>
HTML;
?>

and header.php looks like this:

<?php
echo <<<HTML
<html>
 <head>
  <title>This is index.php</title>
 </head>
HTML;
}

The resulting code for index.php is:

<html>
 <head>
  <title>This is index.php</title>
 </head>
 <body>
 </body>
<html>

It treats all the includes as 'one page'.  So it's no big deal really which page you have it on, if pages/page.php has all the code on it, then by all means include it on there.  You still have to capture the 'id' from the URL and specify where on the page you want the list of hotels displayed.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#18 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 09:46 AM

ok so i put the include on the pages page, but it shows this error

   
Parse error: parse error, unexpected '{' in

which is on this line of the include:

if (isset($_GET['id']){



#19 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 15 September 2006 - 09:49 AM

Change this:
if (isset($_GET['id']){

to this:
if (isset($_GET['id'])){
<- Notice the extra parenthesis

If this was in the code I wrote, I apologise.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#20 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 09:57 AM

ok now there seem tobe something wrong with this line

include('hotel.php');

it says

main(hotel.php): failed to open stream: No such file or directory

so i also tried:

include('pages/hotel.php');

, and also, when i click on a region name it goes onto the index page, but i assume this is the reason why




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users