ltoto Posted September 14, 2006 Share Posted September 14, 2006 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, countryNametabRegion - Id, countryId, regionNametabHotel - Id, regionId, hotelName, hotelImage, hotelDescription, hotelRatingso what i am doing is a system like the example on this website:http://212.161.124.21/hotellist.aspi 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[code]<?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;}?>[/code]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.... Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 14, 2006 Share Posted September 14, 2006 hotels.php needs the following:[code]<?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"}[/code]Huggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 14, 2006 Author Share Posted September 14, 2006 [code]$id = $_GET['Id'];[/code]this is the bit that is not working now, i did change $id to $Id aswell which didnt seem to work Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 14, 2006 Share Posted September 14, 2006 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 [code=php:0]<a href="../pages/hotels.php?id=5">Greece</a>[/code]Huggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 14, 2006 Author Share Posted September 14, 2006 /pages/hotels.php?Id=1annd the id changes with each one to the correct id Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 14, 2006 Share Posted September 14, 2006 OK, so we know it's getting the right id...So on your hotel.php, if you type this:[code]<?php $id = $_GET['Id']; echo $id;?>[/code]Does it echo the correct values... Try clicking a couple of regions from the previous page.Huggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 14, 2006 Author Share Posted September 14, 2006 ok i will have to get back to you tommorrow, because it is now hometime, thanks for all the help today though Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 14, 2006 Share Posted September 14, 2006 No problem, my pleasure.Huggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 ok, so it does echo the correct values Quote Link to comment Share on other sites More sharing options...
markbett Posted September 15, 2006 Share Posted September 15, 2006 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.... Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 ahhhh i seem to of gotten it working now, thanks for the help Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 15, 2006 Share Posted September 15, 2006 What was it Itoto?RegardsHuggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 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 pagei would use this normally because iput most things in one page[code]<?php include 'pages/page.php'; ?>[/code], but obviously i just want it to appear when they click on the region name Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 Right this is the code at the moment [code]<?phpmysql_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";}?><?phpmysql_free_result($rsHotel);?>[/code]which brings Undefined Variable errors, so Im assuming this means i have done something wrong with the include on the index page Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 15, 2006 Share Posted September 15, 2006 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.[code]<?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;}?>[/code]Then where you want your list of hotels to appear on your index.php page, have this:[code]if (isset($_GET['id']){ $id = $_GET['id']; include('hotel.php');}[/code]and your hotel.php looks like this:[code]<?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";}?>[/code]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 i forgot to explain something sorry, on the index page, there is an include to pages page like this[code]<?php include 'pages/page.php'; ?>[/code]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.phpdoes that make any sense? Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 15, 2006 Share Posted September 15, 2006 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:[code]<?phpinclude('header.php');echo <<<HTML; <body> </body><html>HTML;?>[/code]and header.php looks like this:[code]<?phpecho <<<HTML<html> <head> <title>This is index.php</title> </head>HTML;}[/code]The resulting code for index.php is:[code]<html> <head> <title>This is index.php</title> </head> <body> </body><html>[/code]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.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 ok so i put the include on the pages page, but it shows this error Parse error: parse error, unexpected '{' inwhich is on this line of the include:[code]if (isset($_GET['id']){[/code] Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 15, 2006 Share Posted September 15, 2006 Change this: [code=php:0]if (isset($_GET['id']){[/code]to this: [code=php:0]if (isset($_GET['id'])){[/code] <- Notice the extra parenthesisIf this was in the code I wrote, I apologise.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 ok now there seem tobe something wrong with this lineinclude('hotel.php');it saysmain(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 Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 15, 2006 Share Posted September 15, 2006 You will need to include the path in the include yes.As for the error, I'm assuming your include structure is like this... [b][color=green][pre]|- index.php -| |- include(pages.php) - | |- include(hotel.php)[/pre][/color][/b]So your index.php includes pages.php (which happens to be in a seperate directory named pages) and pages.php includes hotel.php (which is in the same directory as pages.php). Is this correct?RegardsHuggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 yes this is correct Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 i made a misatake, i put hotel.php, but it is hotels .phpbut there is still a problem, which is, thi results now appear on the index page, or the home page when you click on the link, instead of it being on its own page Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 15, 2006 Share Posted September 15, 2006 ok, create the following three new pages and tell me if it works as expected:[b]index.php[/b][code]<?phpinclude('connect.php') // This is the name of your db connection fileinclude('/pages/page.php');?>[/code][b]pages.php[/b] - In the pages directory[code]<?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;}if (isset($_GET['id']){ $id = $_GET['id']; include('hotel.php');}?>[/code][b]hotel.php[/b] - In the pages directory along side pages.php[code]<?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";}?>[/code]If you then goto index.php you should get a list of countries and their regions listed below. When you click on one of the regions, index.php should reload with the same list of countries and regions, but also the hotels you selected below them.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
ltoto Posted September 15, 2006 Author Share Posted September 15, 2006 sorry, just want to ask if you posted this without seeing my post above becuase the er posted around similar times? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.