php+ajax城市联动 ?php /* 表结构---- 表的结构 `web_city`--CREATE TABLE IF NOT EXISTS `web_city` ( `id` mediumint(8) NOT NULL AUTO_INCREMENT, `title` varchar(60) NOT NULL, `pid` mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) ENGINE=M
php+ajax 城市联动
<?php /* 表结构 -- -- 表的结构 `web_city` -- CREATE TABLE IF NOT EXISTS `web_city` ( `id` mediumint(8) NOT NULL AUTO_INCREMENT, `title` varchar(60) NOT NULL, `pid` mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; -- -- 转存表中的数据 `web_city` -- INSERT INTO `web_city` (`id`, `title`, `pid`) VALUES (1, '北京', 0), (2, '东单', 1), (3, '西单', 1); */ $my_db = mysql_connect("localhost","root",""); mysql_select_db("city", $my_db); mysql_query("set names 'utf8'"); $sql = "select * from web_city where pid = 0"; $query = mysql_query($sql); $provice = array(); while($row = mysql_fetch_assoc($query)) { $provice[] = $row; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>php+ajax 城市联动</title> <script src="jquery-1.8.0.min.js"></script> </head> <body> <script> function select_city(){ var id = jQuery("#provice option:selected").val(); $("#city").html('<option value="">选择市</option>'); $.ajax({ type: "post", url: "ajax.php", data: "id="+id, dataType: "json", success: function(msg){ var tbody = ""; $.each(msg.optionss,function(n,value){ var trs = ""; trs += "<option value='"+ value.id +"'>"+value.title+"</option>"; tbody += trs; }) $("#city").append(tbody); } }); } </script> <div> <select name="provice" id="provice" onchange="select_city()"> <option value="">选择省/市</option> <?php foreach($provice as $val){?> <option value="<?php echo $val['id'];?>"><?php echo $val['title'];?></option> <?php }?> </select> <select name="city" id="city"> <option value="">选择市</option> </select> </div> </body> </html>
<?php $my_db = mysql_connect("localhost","root",""); mysql_select_db("city", $my_db); mysql_query("set names 'utf8'"); if(isset($_POST['id'])){ $id = $_POST['id']; $sql_city = "select * from web_city where pid = $id"; $query_city = mysql_query($sql_city); $city = array(); while($row = mysql_fetch_assoc($query_city)) { $city[] = $row; } echo json_encode(array('optionss'=>$city)); } ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.