By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

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

P: 5
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.
Apr 6 '10 #1
Share this Question
Share on Google+
1 Reply

code green
Expert 100+
P: 1,726
You are going to need something like a `country` table with an ID
Expand|Select|Wrap|Line Numbers
  1. country_id    country
  2. 0            India
  3. 1            US
  4. 2            South Africa
  5. ...etc
Then a States table
Expand|Select|Wrap|Line Numbers
  1. states
  2. country_id    state
  3. 1          Alabama
  4. 1          Arkansas
  5. 1          California
  6. etc.......
Then you can populate the drop down boxes from a query
Apr 6 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.