Jump to content


Photo

Linking to Specific Id's


  • Please log in to reply
33 replies to this topic

#21 HuggieBear

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

Posted 15 September 2006 - 10:09 AM

You will need to include the path in the include yes.

As for the error, I'm assuming your include structure is like this...

[pre]
|- index.php -|
              |- include(pages.php) - |
                                      |- include(hotel.php)
[/pre]


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?

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

#22 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 10:11 AM

yes this is correct

#23 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 10:38 AM

i made a misatake, i put hotel.php, but it is hotels .php

but 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

#24 HuggieBear

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

Posted 15 September 2006 - 10:38 AM

ok, create the following three new pages and tell me if it works as expected:

index.php
<?php
include('connect.php') // This is the name of your db connection file
include('/pages/page.php');
?>

pages.php - In the pages directory
<?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');
}
?>

hotel.php - In the pages directory along side pages.php
<?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";
}
?>

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.

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

#25 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 10:41 AM

sorry, just want to ask if you posted this without seeing my post above becuase the er posted around similar times?

#26 HuggieBear

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

Posted 15 September 2006 - 10:55 AM

I didn't see that... It doesn't make sense now.  In one post you said this:

Also a quick question, what include would i put on the index page for the hotels page, i would use this normally because i put most things in one page


Now you're saying:

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


Tell me what you want on each page and we'll work out how you need to do it.

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

#27 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 11:00 AM

ok, so i want the hotels to appear, like , on its own blank page so there is no other content, but it to still be an include, obviously so the design is around it, because at the moment, you click on the region, and the list of hotels within it would appear on the page people see when they first come on the site

#28 HuggieBear

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

Posted 15 September 2006 - 11:23 AM

Do you have individual navigation/design elements on seperate pages that you include?

e.g Index.php includes header.php, navigation.php, sidebar.php etc.

If so, then create a new page called hotellist.php with ecah of those elements on it and still include pages.php for the content.

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

#29 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 12:10 PM

i have a page (page.php) for where all the content of the site is displayed, and a page called left.php, which has the menu on it, and if you remember the site it, that page also has the latest deals list on it....

#30 HuggieBear

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

Posted 15 September 2006 - 12:26 PM

OK, I remember, I'm guessing you only have one page at the moment though?  If you had more than one page you'd have come up against this sooner.

The problem you have is that you want the content for every page on pages.php and then just to include that in the rest of the pages across the site.  If that's the case then you need lots of conditional IF statements on pages.php like I mentioned earlier.

Create hotels.php and include pages.php on it.  Then change the links in index.php

From:
<a href="{$_SERVER['PHP_SELF']}?id={$row['Id']}">{$row['regionName']}</a><br>
To:
<a href="pages/hotels.php?id={$row['Id']}">{$row['regionName']}</a><br>

This should still work with the index.php and pages.php that I provided in the earlier post.

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

#31 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 12:31 PM

i have other pages with content on now, i have pages table in the database, so maybe i could add a page in that called hotels list, or would this not work

#32 HuggieBear

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

Posted 15 September 2006 - 12:33 PM

Oh right, what does the pages table contain then?

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

#33 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 12:38 PM

this is how it is in the sql

tabPages:

id
pagesTitle
pagesName
pagesContent
pagesDate

then on the menu in the front end i have the names of the pages listed, for the menu  but not in a repeat region because ihave used different icons for each menu image,

#34 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 September 2006 - 01:52 PM

i was thinking that if i added a new page, then all we would need to do is change the include so that in it it has

index.php?Id=16 (this would be the hotelistpage)

so i thought i could some hwo add that to this

<?
if  (isset($_GET['id'])){
  $id = $_GET['id'];
  include('pages/hotels.php');
}
?>

and also have to change this link here aswell

"{$_SERVER['PHP_SELF']}?id={$row['Id']}">{$row['regionName']}

any suggestions anyone ? or do i need to go into more detail






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users