forumnz Posted January 1, 2008 Share Posted January 1, 2008 I'm creating a site that includes a search. Now, I am familiar with searches etc. The site has places people can visit in different areas. There are three dropdown boxes. The first is Regions. The user clicks on say region A, which loads all the cities in dropdown box 2 within that region. User selects city A (example) which loads all suburbs in that city. I have all that fine and worked out, but how would I select the right stuff from the database depending on the area? Each area has a value (like 233). How would I get the script to select All Suburbs within a city? I dont need code, just some theory. Thanks a lot, Sam. Quote Link to comment https://forums.phpfreaks.com/topic/83917-need-some-theory/ Share on other sites More sharing options...
psychowolvesbane Posted January 1, 2008 Share Posted January 1, 2008 Well first off you would need a relational database with at least 3 different tables, one for each different Regions, Cities, and Suburbs. Then you would need a table between each (Say between Regions and Cities) to determine which City goes with what Region, and do the same with the Suburbs for each City. That will get you a decent normalized Database to play with. Quote Link to comment https://forums.phpfreaks.com/topic/83917-need-some-theory/#findComment-427065 Share on other sites More sharing options...
forumnz Posted January 1, 2008 Author Share Posted January 1, 2008 Is there an easier way? I have thousands of areas! ??? ??? ??? Thanks, Sam. Quote Link to comment https://forums.phpfreaks.com/topic/83917-need-some-theory/#findComment-427066 Share on other sites More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 They aren't many-to-many relationships, so you don't need those intermediate tables that psychowolvesbane suggested Data schema [pre] region city suburb place --------- -------- ---------- ---------- regionID --+ cityID --+ suburbID ----+ placeID region | city | suburb | placename +- regionID +- cityID +--- suburbID [/pre] To find all places in $city SELECT c.city, s.suburb, p.placename FROM place p INNER JOIN suburb s ON s.suburbID = p.suburbID INNER JOIN city c ON c.cityID = s.cityID WHERE cityID = '$city' Quote Link to comment https://forums.phpfreaks.com/topic/83917-need-some-theory/#findComment-427202 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.