Jump to content


Photo

SOLVED 2 Repeat Regions


  • Please log in to reply
71 replies to this topic

#61 HuggieBear

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

Posted 14 September 2006 - 12:14 PM

oh ok, my bad.  I'm looking again now.

Rich
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

#62 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 12:15 PM

oops i also just deleted my post , because iwas gonna post again so i didnt double post,

ok, hopefully the problem can be sorted out with your help, i am hoping this part of the site can be done for around 530 pm today :)

#63 HuggieBear

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

Posted 14 September 2006 - 12:41 PM

ok, try replacing all of your code that gets the countries and regions with this:

<?php
// Your select to get all the data, I've tried to remember your column/table data
$sql="SELECT c.countryName, r.regionName, r.regionID FROM tblCountry c, tblRegion r WHERE c.countryID = r.countryID";
$result = mysql_query($sql);
$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="hotels.php?regionid=$row[regionID]">$row[regionName]</a><br>
HTML;
}
?>

See example here: http://www.dizzie.co.uk/php/pages2.php

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

#64 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 12:45 PM

i got this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

from this line

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){



#65 HuggieBear

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

Posted 14 September 2006 - 12:49 PM

ok, add error checking then...

<?php
// Your select to get all the data, I've tried to remember your column/table data
$sql="SELECT c.countryName, r.regionName, r.regionID FROM tblCountry c, tblRegion r WHERE c.countryID = 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="hotels.php?regionid=$row[regionID]">$row[regionName]</a><br>
HTML;
}
?>

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

#66 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 12:53 PM

what is the r. bit for, do i keep that or just replace it

#67 HuggieBear

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

Posted 14 September 2006 - 12:54 PM

They're table aliases... Because we're joining to another table, it's shorter than specifying the whole table name.

Rich
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

#68 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 01:05 PM

wahay, it is working, thanks a lot man, i think i understand most of it now aswell which is good, so now i just put the code on the hotel page which you gave before and this section s complete

#69 HuggieBear

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

Posted 14 September 2006 - 01:12 PM

I hope so ;)

Well done for persevering.

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

#70 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 01:29 PM

i dont seem to be able to find the code now though, did it get deleted, or am i just being blind?

#71 HuggieBear

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

Posted 14 September 2006 - 01:50 PM

Did you have any code for a hotel page yet?  I don't think I've seen any...

It might be an idea to mork this thread as solved and then start a new one with any hotel related pages, as this is getting quite long now.

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

#72 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 02:06 PM

right ok, will do, maybe i shall see you there  ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users