php-联动下拉列表 和 php、htm之间传值
dis.htm
<br /><div class="newdestination_city"><br /> <span>目的地所属城市</span> <select name="content"><br /> <option value="0">大洲</option><br /> <!--{loop $content $con}--><br /> <option value='$con[districtid]'>$con[name]</option><br /> <!--{/loop}--><br /> </select> <select name="country"><br /> <option value="0">国家</option><br /> <!--{loop $country $cou}--><br /> <option value='$cou[districtid]'>$cou[name]</option><br /> <!--{/loop}--><br /> </select> <select name="district"><br /> <option value="0">区域</option><br /> <!--{loop $district $dis}--><br /> <option value='$dis[districtid]'>$dis[name]</option><br /> <!--{/loop}--><br /> </select> <select name="province"><br /> <option value="0">省份</option><br /> <!--{loop $province $pro}--><br /> <option value='$pro[districtid]'>$pro[name]</option><br /> <!--{/loop}--><br /> </select> <select name="city"><br /> <option value="0">城市</option><br /> <!--{loop $city $ci}--><br /> <option value='$ci[districtid]'>$ci[name]</option><br /> <!--{/loop}--><br /> </select><br /> </div><br />
dis.php
<br />//……<br />$country=getBycontent($content);<br />$pro=getBycountry($country);<br />//……<br />

我想让第一个下拉列表被选之后出现第二个下拉列表,并且根据第一个下拉列表中被选择的选项搜索出第二个下拉列表的列表项。请问怎么才能在这两个文件之间传值呢?
------解决思路----------------------
demo.php
<br /><html><br /><head><br /><meta http-equiv="content-type" content="text/html; charset=utf-8"><br /><title>demo</title><br /><script src="//code.jquery.com/jquery-1.11.0.min.js"></script><br /></head><br /><body><br /><br /><script type="text/javascript"><br />var data = [];<br />function sel(v, c){<br /> $.get("server.php", { parent: v, type: c },function(ret){<br /> if(ret.success==true){<br /> var list = ret.list;<br /> var selobj = document.getElementById('sel'+(c+1));<br /> for (i=1;i<list.length;i++){<br /> selobj.options[i] = new Option(list[i].name,list[i].id);<br /> }<br /> }<br /> },'json');<br /><br />}<br /></script><br /><br /><form name="f1"><br /><select name="select1" id="sel1" onchange="sel(this.value, 1)"><br /><option value="0">大洲</option><br /><option value="1">亚洲</option><br /><option value="2">欧洲</option><br /></select><br /><select name="select2" id="sel2" onchange="sel(this.value, 2)"> <br /><option value="0">国家</option> <br /></select><br /><select name="select3" id="sel3" onchange="sel(this.value, 3)"><br /><option value="0">区域</option><br /></select><br /><select name="select4" id="sel4" onchange="sel(this.value, 4)"><br /><option value="0">省份</option><br /></select><br /><select name="select5" id="sel5"><br /><option value="0">城市</option><br /></select><br /><br /></form> <br /></body><br /></html><br />
server.php
<br /><?php<br />$parent = isset($_GET['parent'])? $_GET['parent'] : 0;<br />$type = isset($_GET['type'])? $_GET['type'] : 0;<br /><br />$sel = array();<br />$sel[1][1] = array('',array('id'=>1,'name'=>'中国'),array('id'=>2,'name'=>'日本'));<br />$sel[1][2] = array('',array('id'=>3,'name'=>'英国'),array('id'=>4,'name'=>'法国'));<br /><br />$sel[2] = array();<br />$sel[2][1] = array('',array('id'=>1,'name'=>'南方'),array('id'=>2,'name'=>'北方'));<br />$sel[2][2] = array('',array('id'=>3,'name'=>'南边'),array('id'=>4,'name'=>'北边'));<br />$sel[2][3] = array('',array('id'=>5,'name'=>'南部'),array('id'=>6,'name'=>'北部'));<br />$sel[2][4] = array('',array('id'=>7,'name'=>'南岸'),array('id'=>8,'name'=>'北岸'));<br /><br />$sel[3] = array();<br />$sel[3][1] = array('',array('id'=>1,'name'=>'中国省1'),array('id'=>2,'name'=>'中国省2'));<br />$sel[3][2] = array('',array('id'=>3,'name'=>'中国省3'),array('id'=>4,'name'=>'中国省4'));<br />$sel[3][3] = array('',array('id'=>5,'name'=>'日本省1'),array('id'=>6,'name'=>'日本省2'));<br />$sel[3][4] = array('',array('id'=>7,'name'=>'日本省3'),array('id'=>8,'name'=>'日本省4'));<br />$sel[3][5] = array('',array('id'=>9,'name'=>'英国省1'),array('id'=>10,'name'=>'英国省2'));<br />$sel[3][6] = array('',array('id'=>11,'name'=>'英国省3'),array('id'=>12,'name'=>'英国省4'));<br />$sel[3][7] = array('',array('id'=>13,'name'=>'法国省1'),array('id'=>14,'name'=>'法国省2'));<br />$sel[3][8] = array('',array('id'=>15,'name'=>'法国省3'),array('id'=>16,'name'=>'法国省4'));<br /><br />$sel[4] = array();<br />$sel[4][1] = array('',array('id'=>1,'name'=>'中国市11'),array('id'=>2,'name'=>'中国市12'));<br />$sel[4][2] = array('',array('id'=>3,'name'=>'中国市21'),array('id'=>4,'name'=>'中国市22'));<br />$sel[4][3] = array('',array('id'=>5,'name'=>'中国市31'),array('id'=>6,'name'=>'中国市32'));<br />$sel[4][4] = array('',array('id'=>7,'name'=>'中国市41'),array('id'=>8,'name'=>'中国市42'));<br />$sel[4][5] = array('',array('id'=>9,'name'=>'日本市11'),array('id'=>10,'name'=>'日本12'));<br />$sel[4][6] = array('',array('id'=>11,'name'=>'日本21'),array('id'=>12,'name'=>'日本22'));<br />$sel[4][7] = array('',array('id'=>13,'name'=>'日本31'),array('id'=>14,'name'=>'日本32'));<br />$sel[4][8] = array('',array('id'=>15,'name'=>'日本41'),array('id'=>16,'name'=>'日本42'));<br />$sel[4][9] = array('',array('id'=>17,'name'=>'英国市11'),array('id'=>18,'name'=>'英国市12'));<br />$sel[4][10] = array('',array('id'=>19,'name'=>'英国市21'),array('id'=>20,'name'=>'英国市22'));<br />$sel[4][11] = array('',array('id'=>21,'name'=>'英国市31'),array('id'=>22,'name'=>'英国市32'));<br />$sel[4][12] = array('',array('id'=>23,'name'=>'英国市41'),array('id'=>24,'name'=>'英国市42'));<br />$sel[4][13] = array('',array('id'=>25,'name'=>'法国市11'),array('id'=>26,'name'=>'法国市12'));<br />$sel[4][14] = array('',array('id'=>27,'name'=>'法国市21'),array('id'=>28,'name'=>'法国市22'));<br />$sel[4][15] = array('',array('id'=>29,'name'=>'法国市31'),array('id'=>30,'name'=>'法国市32'));<br />$sel[4][16] = array('',array('id'=>31,'name'=>'法国市41'),array('id'=>32,'name'=>'法国市42'));<br /><br />$list = $sel[$type][$parent];<br /><br />$ret = array();<br />$ret['success'] = true;<br />$ret['list'] = $list;<br />echo json_encode($ret);<br /><br />?><br />
server.php可改成读数据库的,这样更方便。

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor