Jump to content


Photo

Recordsets help


  • Please log in to reply
13 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 12 September 2006 - 02:25 PM

Basically what i am tryin to do is somethiing where

i have a recordset for counties, one for Citys and one for Schools, and with the school one you can select its county and city, in the backend.

so in the front end i now on one page want the list of Countys to list up, which i am guessing i will just use the coutys recordsent and repeat the country name.

and i will need to list the Citys in each county, but obviously i cant put a recordset within a record, which i where i get confused to what record set yo use ect .

and when i click on the city, it then goes onto a new page and lists the schools, which also confuses me


this is the code i have so far:

<?  if($row_rsPages['Id']== "15") { ?>
<?php do { ?>
<h2><?php echo $row_rsCounty['countyName']; ?></h2>
<?php echo $row_rsCity['cityName']; ?>
<?php } while ($row_rsCounty = mysql_fetch_assoc($rsCounty));  ?>
<?php } ?>


any ideas...

do i just use the code that adam gave me or do something else

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 02:32 PM

Welcome to the forums, please use a more descriptive title when creating threads!  Thanks!

As far as your code... you're jumping in and out of PHP WAAAAAAY too much.  You should also never use a do... While loop.  You're forcing the code to run no matter what the first time.  If the code doesn't need to run the first time, you're going to get errors.

New code:
<?php  if($row_rsPages['Id']== "15") 
{  
  while ($row_rsCounty = mysql_fetch_assoc($rsCounty))
  {
       extract($row_rsCounty);
       echo "<h2>$countyName</h2>$cityName";
  }
} 
?>

As far as the logic, you may need to describe the problem a little better.  What are you expecting for output and what is your input?

Info: PHP Manual


#3 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 12 September 2006 - 02:37 PM

basically, this is want i want, a system like this

http://212.161.124.21/hotellist.asp

so one one page there will be alist of Countys, and with the Countys it lists the cities with the counties, they will then be able to click on one of the cities, where a new page will load, with a list of schools from that city

hope that describes it better

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 02:42 PM

Alright.  So you have your selection on the first page.  On the next page you want something like this:
<?php
$query = "SELECT schools FROM school_table WHERE city_id = '" . $_POST['city_id'] . "'";
$result = mysql_query($query) or die(mysql_error());
if($result && mysql_num_rows($result) > 0)
{
   while($row = mysql_fetch_assoc($result))
   {
         extract($row);
         echo "$school_name<br/>";
    }
}
?>

Does that help?  Also, you have to make your city names into links that link to this page with the ID value of the city... or you create a form with a drop-down that submits to this page.

Info: PHP Manual


#5 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 12 September 2006 - 02:44 PM

i have done the form with the drop down in the back, so when they enter a school, they can choose a city and the County

#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 02:45 PM

Ok... so... does the code I gave you help?

Info: PHP Manual


#7 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 12 September 2006 - 02:49 PM

i just tried the first bit but it comes up with this error

Notice: Undefined variable: cityName

would this be because in the code

<?php  if($row_rsPages['Id']== "15")

  while ($row_rsCounty = mysql_fetch_assoc($rsCounty))
  {
      extract($row_rsCounty);
      echo "<h2>$countyName</h2>$cityName";
  }
}
?>

the rsCity is not named? so it cant find the cityName, because the cityName is from the rsCity

#8 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 03:05 PM

If rsCity is available and you have used mysql_fetch_assoc on it, you need to extract that as well.

I was trying to give you an example of how to do it.  You need to manipulate it to match your own coding.

Info: PHP Manual


#9 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 12 September 2006 - 03:08 PM

i figured that bit out now cheers, the only probelm is that it is not repeating now, so you can only see one city

#10 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 03:10 PM

Can you post your latest code?

Info: PHP Manual


#11 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 12 September 2006 - 03:13 PM

here it is

<?php  if($row_rsPages['Id']== "15")

  while ($row_rsCounty = mysql_fetch_assoc($rsCounty))
 
  {
      extract($row_rsCounty);
  extract($row_rsCity);
      echo "<h2>$countyName</h2>$cityName";
  }
}
?>

#12 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 03:16 PM

Ok... well I'm going to assume that you only have one county at this point and you want to be putting the City recordset in the while loop instead.  Also, to save some processor time, put the extraction of the county recordset outside of the while loop and set it's value equal to a variable that you use in the while loop.  (I'm not sure why you want to list the county each time... but whatever.)

Info: PHP Manual


#13 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 12 September 2006 - 03:19 PM

I have two Citys added to the datebase at the moment

i want to list the list of countys each time, i want it to list a different county each time

btw just to point out, you have been a great help so far, best on the net i have recieved, i will post here alot more often

#14 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 12 September 2006 - 03:59 PM

I am still struggling with basically getting a repeat regin within anothe repeat region

<?php  if($row_rsPages['Id']== "15")
{
  while ($row_rsCounty = mysql_fetch_assoc($rsCounty))

  {
      extract($row_rsCounty);
      extract($row_rsCity);
      echo "<h2>$countyName</h2>$cityName";
  }
}
?>

so that works fine, but ialso need to repeat the rsCity which is inside the County repeat region




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users