展开全部
思路大概就是,在第一个下拉菜单里中添加change事件的监听,然后在触发62616964757a686964616fe4b893e5b19e31333337383334change时向后台发送一个ajax请求,然后通过后台返回的内容,动态更新第二个下拉列表
等下给你上例子
我用的是ADODB连接的 SQL Server至于怎么连数据库,你就自己看着办吧
前台html>
无标题文档require_once('../include/SQL_inc/adodb5/adodb.inc.php');
$SQL_connect_str = "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER={KASIM-PC\SQLEXPRESS};DATABASE=mytest;UID=sa;PWD=sa";
$db = NewADOConnection("ado_mssql");
$db->Connect($SQL_connect_str);
$db->Execute("set names utf8");
?>
$sqlFlist = "SELECT DISTINCT firstList from list";
$result = $db->Execute($sqlFlist);
while(!$result->EOF){
echo "".mb_convert_encoding($result->fields[0], "UTF-8", "GBK")."";
$result->MoveNext();
}
?>
$("#list1").change(function(e) {
$.ajax({
url:"back.php",
type:"POST",
data:{key:$("#list1").val()},
dataType:"json",
success: function(backdata){
inner = "";
for(i = 0; i
inner+=""+backdata[i]+"";
inner += "";
$("#list2box").html(inner);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(textStatus);
}
});
});
后台<?php
if(isset($_POST['key'])){
require_once('../include/SQL_inc/adodb5/adodb.inc.php');
$SQL_connect_str = "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER={KASIM-PC\SQLEXPRESS};DATABASE=mytest;UID=sa;PWD=sa";
$db = NewADOConnection("ado_mssql");
$db->Connect($SQL_connect_str);
$db->Execute("set names utf8");
$sqlstr = "select dtl from list where firstList = '".mb_convert_encoding($_POST['key'], "GBK", "UTF-8")."'";
$result = $db->Execute($sqlstr);
$backValue = array();
$i = 0;
while(!$result->EOF){
$backValue[$i] = $result->fields[0];
$result->MoveNext();
$i++;
}
echo json_encode($backValue);
}