Home > Web Front-end > JS Tutorial > body text

jQuery combined with PHP MySQL to implement secondary linkage drop-down list [Example]_jquery

WBOY
Release: 2016-05-16 17:59:30
Original
1309 people have browsed it

jQuery结合PHP-MySQL实现二级联动下拉列表 学生信息表的实例

Implementation principle: According to the change of province value, sf_id is passed to the background php file for processing through jQuery. PHP queries the MySQl database to get the corresponding city name, and returns JSON data to the front-end for processing, that is, the linkage effect is achieved!

For the convenience of explanation, the provinces are given directly here: Henan Province (sf_id=1) Zhejiang Province (sf_id=2), and two data tables are created for city and student information respectively! The encoding methods are all: utf8! Create a new database and execute the following SQL statements!

Copy code The code is as follows:

/* City table*/
create TABLE IF NOT EXISTS `dishi`(
`ds_id` int(3) auto_increment not null primary key,
`sf_id` int(3) not null default '0',
`ds_name` varchar(50) not null
);
/* student table*/
create TABLE IF NOT EXISTS `xuesheng`(
`xs_id` int(3) auto_increment not null primary key,
`ds_id` int(3) not null default '0',
`xs_name` varchar(50) not null
); Then set up a front desk shelf:

Copy code The code is as follows:











Province

< ;/td>
Prefecture and city

Student name


Then comes the jQuery part. For details, please see the comments after the code:
Copy code The code is as follows:



The select.php is the key part. This file receives the parameter sf_id passed by the front desk through the $.getJSON method, and then select.php obtains the corresponding city data based on the province sf_id, and then returns the JSON data. The front desk uses jQuery to convert the JSON The data is processed and written into
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!