用数据库内容制作二级联动下拉框并跳转

<!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" c />
<title>无标题文档</title>
</head>
<body>
<?php
    require_once (dirname(__FILE__) . "/include/common.inc.php");
    $sql="select * from dede_diydown group by downtype order by downtype asc";
		$dsql->SetQuery($sql);//将SQL查询语句格式化
		$dsql->Execute();//执行SQL操作
//$query1=mysql_query("select * from dede_diydown group by downtype order by downtype asc");
$fMenu="";
$fValue="";
//while($data1=mysql_fetch_array($query1)){
		while($data1=$dsql->GetArray()) {
$fMenu.="\"".$data1[downtype]."\",";
$fValue.="\"".$data1[downtype]."\",";

}
$fMenu=substr($fMenu,0,(strlen($fMenu)-1));
$fMenu="[".$fMenu."]";//*****************************得到var fMenu
$fValue=substr($fValue,0,(strlen($fValue)-1));
$fValue="[".$fValue."]";//*****************************得到var fValue

//得到*****************************var sMenu
$query1=mysql_query("select * from dede_diydown group by downtype order by downtype asc");
while($data1=mysql_fetch_array($query1)){
$province_id1=$data1[downtype];

$query2=mysql_query("select * from dede_diydown where downtype='$province_id1'");

while($data2=mysql_fetch_array($query2)){
$num=mysql_num_rows($query2);
$i++;
$sMenu.="\"".$data2[downsn]."\",";
if($i==$num){
$sMenu="[".$sMenu."],[";
$i=0;
}
}
}
$sMenu.="]";
$sMenu=str_replace("\",]","\"]",$sMenu);
$sMenu=str_replace(",[]","]",$sMenu);
if((substr($sMenu,0,2))=="[\""){
$sMenu="[".$sMenu;
}else{
$sMenu=preg_replace("/\[{3,}/is","[[\\1",$sMenu);//匹配
}

//得到*****************************var sValue
$query1=mysql_query("select * from dede_diydown group by downtype order by downtype asc");
while($data1=mysql_fetch_array($query1)){
$province_id=$data1[downtype];
$sql="select * from dede_diydown where downtype='$province_id'";
// echo $sql;
$query2=mysql_query($sql);
while($data2=mysql_fetch_array($query2)){
$nums=mysql_num_rows($query2);
$j++;
$sValue.="\"".$data2[downaddr]."\",";
if($j==$nums){
$sValue="[".$sValue."],[";
$j=0;
}
}
}
$sValue.="]";
$sValue=str_replace("\",]","\"]",$sValue);
$sValue=str_replace(",[]","]",$sValue);
if((substr($sValue,0,2))=="[\""){
$sValue="[".$sValue;
}else{
$sValue=preg_replace("/\[{3,}/is","[[\\1",$sValue);//匹配
}

?>
<br><br>
<div id=a>请选择手机品牌与型号:
<span id="tar"></span></div><span style="text-aling:center;backgroud-color:#ff0055;">选择即可下载相应软件
</span><br><br>
<SCRIPT LANGUAGE="JavaScript" DEFER>
var fMenu = <?php echo $fMenu; ?>;
var fValue = <?php echo $fValue; ?>;
var sMenu = <?php echo $sMenu; ?>;
var sValue = <?php echo $sValue; ?>;

var oWhere = document.all.tar;
var ofMenu = document.createElement("<SELECT name='bigclass'>");
var osMenu = document.createElement("<SELECT name='smallclass' id='smallclass'>");
with(oWhere)appendChild(ofMenu),appendChild(osMenu);

createMainOptions();
createSubOptions(0);

ofMenu.onchange = function() {createSubOptions(this.selectedIndex);};
function createMainOptions() {
for(var i=0;i<fMenu.length;i++)ofMenu.options[i] = new Option(fMenu[i],fValue[i]);
}

function createSubOptions(j) {
with(osMenu) {
length=0;
for(var i=0;i<sMenu[j].length;i++)osMenu.options[i] = new Option(sMenu[j][i],sValue[j][i]);
}
}
osMenu.onchange = function () { goUrl(this.options[this.selectedIndex].value);};
function goUrl(str)
{
	window.open(str);

}
</SCRIPT>

</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值