[英]populate select tag in php
I have a many masters in my project of the basic one is country,state and city. 我的基本项目中有很多硕士是国家,州和城市。 i have added/inserted the records in mysql database but when i want to edit record how can i populate the state select tag when the country is selected from mysql database?
我已经在mysql数据库中添加/插入了记录,但是当我想编辑记录时,当从mysql数据库中选择国家时,如何填充状态选择标签?
For example i have a record in city table as 例如我在城市表中有一条记录为
╔════╦══════════════╦════
║ COUNTRY║ STATE║ CITY ║
╠========╬══════════════╬
║ INDIA ║ PUNJAB║ ABC ║
║ INDIA ║ J&K ║ PQR ║
║ USA ║ NJ ║ MNO ║
=========================
NOW when i go for edit operation for say suppose record 1 ie INDIA-PUNJAB-ABC 现在,当我进行假设记录1的编辑操作时,即印度-旁遮普语-ABC
I am able to select INDIA in Country select tag but i am not able to get only INDIA states and select ABC in select tag of state 我可以在“国家/地区”选择标签中选择“印度”,但我不能仅获得印度州,而在“国家/地区”选择标签中选择ABC
However you achieve this, you will need to interrogate the db using the selected COUNTRY. 无论您实现了什么,都将需要使用所选的COUNTRY来查询数据库。 So..
所以..
Option 1 :perform an AJAX request 'onChange' of the COUNTRY to populate the CITY box using Javascript 选项1:执行COUNTRY的AJAX请求“ onChange”以使用Javascript填充CITY框
Option 2 : refresh/submit the page 'onChange'of the COUNTRY and use the posted COUNTRY field to generate a filtered list of CITY options to use in the 选项2:刷新/提交国家/地区的“ onChange”页面,并使用发布的国家/地区字段生成CITY选项的过滤列表,以供在
You need to normalize your data. 您需要规范化数据。 You need tables country and state.
您需要表格国家和州。 And in your table use city_id and state_id or only state_id.
并且在表中使用city_id和state_id或仅使用state_id。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.