php 不同国家、州、地理位置的动态下拉列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26069761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dynamic drop down list for different countries, states, geographic locations?
提问by EternalHour
I am having my users to enter their city, state, and country. But my dilemma is how to manage it dynamically so that I can control what is entered while having correct spelling and formatting.
我让我的用户输入他们的城市、州和国家。但我的困境是如何动态管理它,以便我可以在正确拼写和格式的同时控制输入的内容。
For instance, I currently have a static drop down for each state.
例如,我目前为每个州都有一个静态下拉列表。
<select>
<option name="state" value="AL">Alabama</option>
<option name="state" value="AK">Alaska</option>
<option name="state" value="AZ">Arizona</option>
<option name="state" value="AR">Arkansas</option>
<option name="state" value="CA">California</option>
....
</select>
This works fine obviously, but doesn't scale at all if the user is outside the US. It also falls short in regards to different countries and cities. I have thought of using text fields, then saving them in a separate database and using the JQuery autocomplete plugin for generating the list but it doesn't seem like the best way to do it.
这显然工作正常,但如果用户不在美国,则根本无法扩展。它在不同的国家和城市方面也存在不足。我曾想过使用文本字段,然后将它们保存在一个单独的数据库中,并使用 JQuery 自动完成插件来生成列表,但这似乎不是最好的方法。
回答by icecub
Ok so after several hours I've written an application based on the MySQL world database: MySQL world Setup
好的,几个小时后,我编写了一个基于 MySQL world 数据库的应用程序:MySQL world Setup
The code for the entire application is way to large to put in an answer so I'll provide Pastebin links for each seperate file, aswell as a link to a working example of the script and a download link for the Zip archive.
整个应用程序的代码很大,无法提供答案,因此我将为每个单独的文件提供 Pastebin 链接,以及指向脚本工作示例的链接和 Zip 存档的下载链接。
I'm sure the code can be improved further, but I'll leave that up to you.
我确信代码可以进一步改进,但我会把它留给你。
Requirements: MySQL world Database / jQuery
要求:MySQL世界数据库/jQuery
- index.html: index.html
- style.css: style.css
- country.js: country.js
- dbconnect.php: dbconnect.php
- get_country.php: get_country.php
- get_states.php: get_states.php
- get_city.php: get_city.php
- get_data.php: get_data.php
- index.html: index.html
- style.css:style.css
- country.js: country.js
- dbconnect.php: dbconnect.php
- get_country.php: get_country.php
- get_states.php: get_states.php
- get_city.php: get_city.php
- get_data.php: get_data.php
Working Example:
工作示例:
Zip Archive Download (DB NOT included!):
Zip 存档下载(不包括数据库!):
- selector.zip(currently down)
- Virus Total Analysis of above file
- selector.zip(当前关闭)
- 上述文件的病毒总分析
I'm working on an updated script due to the popular demands on this question. It will be added soon.
由于对这个问题的普遍要求,我正在编写更新的脚本。它很快就会被添加。