City State or Country State from Database in select.....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sahilansari
    New Member
    • Mar 2010
    • 5

    #1

    City State or Country State from Database in select.....

    I have a table in MYSQL database...

    With Country & it's corresponding States.

    Say i select US from the dropdown option it should automatically show all the states in US from a database file.

    I have seen some code examples on the net which do give a solution to the above problem but you have to manually enter all the countries & their states in the code itself.(using javascript)

    I want to do this by accessing database.

    (1)If i select US , my code should access database & get all the states for US.
    (2)If i select India, my code should access database & get all the states for India.


    and so on.
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    You are going to need something like a `country` table with an ID
    Code:
    country_id    country
    0            India
    1            US
    2            South Africa
    ...etc
    Then a States table
    Code:
    states
    country_id    state
    1          Alabama
    1          Arkansas
    1          California
    etc.......
    Then you can populate the drop down boxes from a query

    Comment

    Working...