Jump to content

Archived

This topic is now archived and is closed to further replies.

ltoto

Recordsets help

Recommended Posts

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

Share this post


Link to post
Share on other sites
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:[code]
<?php  if($row_rsPages['Id']== "15")

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

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Alright.  So you have your selection on the first page.  On the next page you want something like this:
[code]<?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/>";
    }
}
?>[/code]

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Ok... so... does the code I gave you help?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
i figured that bit out now cheers, the only probelm is that it is not repeating now, so you can only see one city

Share this post


Link to post
Share on other sites
Can you post your latest code?

Share this post


Link to post
Share on other sites
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";
  }
}
?>

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.