Dizzle Posted November 19, 2010 Share Posted November 19, 2010 I've searched but can't seem to find anything I can apply to this situation. Most of the resources are dedicated to dropdown menu's from the same table. I have two tables 'regions' and 'cities' and I am looking to create a menu that lists all the cities within a region then moves on to do the same for the rest of the regions in that state: State1 Region1 City1 City2 City3 Region2 City1 City2 City3 Region3 Etc My tables: States table: stateID, state Regions table: regionID, region, stateID Cities table: cityID, city, regionID I currently have two pages- select region, then select city... I'd like to consolidate to one step after choosing a state. I know I need a nested loop, (while?), and to count the results somehow to retrigger loop; also not sure how to handle two mySQL querries in the nested loop. I'm having trouble wrapping my mind around it. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/219247-nested-loop-for-cities-in-regions-menu-by-state/ Share on other sites More sharing options...
snowman15 Posted November 19, 2010 Share Posted November 19, 2010 can you explain a little more in depth what your actually trying to pull with what input data? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/219247-nested-loop-for-cities-in-regions-menu-by-state/#findComment-1136953 Share on other sites More sharing options...
WTFranklin Posted November 20, 2010 Share Posted November 20, 2010 If I'm understanding correctly, you'd probably want to do your sql query first and put everything into a multidimensional array, then use a foreach loop to get what you would like out of it in the formatting you need. I hate to give you links to tutorials, but someone else likely worded it better than I can. Here's php.net multidimensional array: http://php.net/manual/en/function.array.php and also foreach loop: http://us2.php.net/manual/en/control-structures.foreach.php Hope that helps some. Quote Link to comment https://forums.phpfreaks.com/topic/219247-nested-loop-for-cities-in-regions-menu-by-state/#findComment-1137003 Share on other sites More sharing options...
Dizzle Posted November 20, 2010 Author Share Posted November 20, 2010 -user clicks 'state' from a static menu on the first page. -"stateID" is then passed through GET where the all the "regions" with that "stateID" are called for... *I'm trying to call for all the "regions" in that "state" AND the "cities" in each "region" all in one step; from different tables. Quote Link to comment https://forums.phpfreaks.com/topic/219247-nested-loop-for-cities-in-regions-menu-by-state/#findComment-1137012 Share on other sites More sharing options...
harristweed Posted November 20, 2010 Share Posted November 20, 2010 I think this is what you are looking for: http://www.felgall.com/jstip22a.htm Quote Link to comment https://forums.phpfreaks.com/topic/219247-nested-loop-for-cities-in-regions-menu-by-state/#findComment-1137037 Share on other sites More sharing options...
Dizzle Posted November 20, 2010 Author Share Posted November 20, 2010 Not looking to make into a form (thanks for the link tho). Something more like this: ***Not dropdown menu, just a menu with the cities as links to city results... WYOMING <--- State selected from previous page... Eastern <--- Region1 Big Horn <---City1 in Region1 Buffalo <--- City2 in Region2 Casper Western <--- Region2 Dubois Lander Jackson Hole Wyoming <--- Region3 Jackson Jackson Hole Pinedale Quote Link to comment https://forums.phpfreaks.com/topic/219247-nested-loop-for-cities-in-regions-menu-by-state/#findComment-1137078 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.