Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/83917-need-some-theory/
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/83917-need-some-theory/#findComment-427065
Share on other sites

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'

Link to comment
https://forums.phpfreaks.com/topic/83917-need-some-theory/#findComment-427202
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.