Jump to content

Recordsets help


ltoto

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.