ltoto Posted September 12, 2006 Share Posted September 12, 2006 Basically what i am tryin to do is somethiing wherei 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 methis 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 Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/ Share on other sites More sharing options...
ober Posted September 12, 2006 Share Posted September 12, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90430 Share on other sites More sharing options...
ltoto Posted September 12, 2006 Author Share Posted September 12, 2006 basically, this is want i want, a system like thishttp://212.161.124.21/hotellist.aspso 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 cityhope that describes it better Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90436 Share on other sites More sharing options...
ober Posted September 12, 2006 Share Posted September 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90438 Share on other sites More sharing options...
ltoto Posted September 12, 2006 Author Share Posted September 12, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90439 Share on other sites More sharing options...
ober Posted September 12, 2006 Share Posted September 12, 2006 Ok... so... does the code I gave you help? Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90441 Share on other sites More sharing options...
ltoto Posted September 12, 2006 Author Share Posted September 12, 2006 i just tried the first bit but it comes up with this errorNotice: Undefined variable: cityNamewould 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 Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90444 Share on other sites More sharing options...
ober Posted September 12, 2006 Share Posted September 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90453 Share on other sites More sharing options...
ltoto Posted September 12, 2006 Author Share Posted September 12, 2006 i figured that bit out now cheers, the only probelm is that it is not repeating now, so you can only see one city Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90456 Share on other sites More sharing options...
ober Posted September 12, 2006 Share Posted September 12, 2006 Can you post your latest code? Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90459 Share on other sites More sharing options...
ltoto Posted September 12, 2006 Author Share Posted September 12, 2006 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"; }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90462 Share on other sites More sharing options...
ober Posted September 12, 2006 Share Posted September 12, 2006 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.) Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90466 Share on other sites More sharing options...
ltoto Posted September 12, 2006 Author Share Posted September 12, 2006 I have two Citys added to the datebase at the momenti want to list the list of countys each time, i want it to list a different county each timebtw 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 Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90471 Share on other sites More sharing options...
ltoto Posted September 12, 2006 Author Share Posted September 12, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/20510-recordsets-help/#findComment-90495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.