首页上一页 1 下一页尾页 1 条记录 1/1页
PHP三级联动列表带数据库(无刷新)无法使用
发表在PHP图书答疑
2009-10-30
是否精华
是
否
版块置顶:
是
否
数据库crm_province(AUTOid,TypeName)、crm_city(ID,province_id,city_title)、crm_area(ID,province_id,city_id,area_title)
注:MYSQL数据库连接正确(即:include_once("../inc/conn.php")文件和路径均完全正确)
<?php include_once("../inc/conn.php");?>
<script language="JavaScript">
<!--
var subval2 = new Array();
<?php
$sqlClass2=mysql_query("select * from crm_city order by ID asc");
$rsClass2=mysql_fetch_array($sqlClass2);
$count2=0;
if($rsClass2!=false)
{
do
{
?>
subval2[<?php echo $count2;?>] = new Array('<?php echo $rsClass2[province_id];?>','<?php echo $rsClass2[ID];?>','<?php echo $rsClass2[city_title];?>');
<?php
$count2=$count2+1;
}
while($rsClass2=mysql_fetch_array($sqlClass2));
}
?>
onecount2=<?php echo $count2;?>;
var subval3 = new Array();
<?php
$sqlClass3=mysql_query("select * from crm_area order by ID asc");
$rsClass3=mysql_fetch_array($sqlClass3);
$count3=0;
if($rsClass3!=false)
{
do
{
?>
subval3[<?php echo $count3;?>] = new Array('<?php echo $rsClass3[city_id];?>','<?php echo $rsClass3[ID];?>','<?php echo $rsClass3[area_title];?>');
<?php
$count3=$count3+1;
}
while($rsClass3=mysql_fetch_array($sqlClass3));
}
?>
onecount3=<?php echo $count3;?>;
function changeselect1(locationid1)
{
document.form1.s2.length = 0;
document.form1.s2.options[0]=new Option('==所属市区==','');
document.form1.s3.length = 0;
document.form1.s3.options[0]=new Option('==所属区县==','');
for (i=0;i<onecount2;i++)
{
if (subval2[i][0]==locationid1)
{document.form1.s2.options[document.form1.s2.length]=new Option(subval2[i][2],subval2[i][1]);}
}
}
function changeselect2(locationid2)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==所属区县==','');
for (i=0;i<onecount3;i++)
{
if (subval3[i][0]==locationid2)
{document.form1.s3.options[document.form1.s3.length]=new Option(subval3[i][2],subval3[i][1]);}
}
}
//-->
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="form1" method="POST" action="a.php">
<tr>
<td width="150">
<select name="s1" onChange="changeselect1(this.value)">
<option>==所属省份==</option>
<?php
$sqlClass1=mysql_query("select * from crm_province order by autoID asc");
$rsClass1=mysql_fetch_array($sqlClass1);
$count1=0;
if($rsClass1!=false)
{
do
{
?>
<option value="<?php echo $rsClass1[autoID];?>"><?php echo $rsClass1[TypeName];?></option>
<?php
$count1++;
}
while($rsClass1=mysql_fetch_array($sqlClass1));
}
?>
</select><font color="#FF0000">*</font></td>
<td width="150"><select name="s2" onChange="changeselect2(this.value)">
<option>==所属市区==</option>
</select><font color="#FF0000">*</font></td>
<td><select name="s3">
<option>==所属区县==</option>
</select><font color="#FF0000">*</font></td>
</tr>
</form>
</table>
注:MYSQL数据库连接正确(即:include_once("../inc/conn.php")文件和路径均完全正确)
<?php include_once("../inc/conn.php");?>
<script language="JavaScript">
<!--
var subval2 = new Array();
<?php
$sqlClass2=mysql_query("select * from crm_city order by ID asc");
$rsClass2=mysql_fetch_array($sqlClass2);
$count2=0;
if($rsClass2!=false)
{
do
{
?>
subval2[<?php echo $count2;?>] = new Array('<?php echo $rsClass2[province_id];?>','<?php echo $rsClass2[ID];?>','<?php echo $rsClass2[city_title];?>');
<?php
$count2=$count2+1;
}
while($rsClass2=mysql_fetch_array($sqlClass2));
}
?>
onecount2=<?php echo $count2;?>;
var subval3 = new Array();
<?php
$sqlClass3=mysql_query("select * from crm_area order by ID asc");
$rsClass3=mysql_fetch_array($sqlClass3);
$count3=0;
if($rsClass3!=false)
{
do
{
?>
subval3[<?php echo $count3;?>] = new Array('<?php echo $rsClass3[city_id];?>','<?php echo $rsClass3[ID];?>','<?php echo $rsClass3[area_title];?>');
<?php
$count3=$count3+1;
}
while($rsClass3=mysql_fetch_array($sqlClass3));
}
?>
onecount3=<?php echo $count3;?>;
function changeselect1(locationid1)
{
document.form1.s2.length = 0;
document.form1.s2.options[0]=new Option('==所属市区==','');
document.form1.s3.length = 0;
document.form1.s3.options[0]=new Option('==所属区县==','');
for (i=0;i<onecount2;i++)
{
if (subval2[i][0]==locationid1)
{document.form1.s2.options[document.form1.s2.length]=new Option(subval2[i][2],subval2[i][1]);}
}
}
function changeselect2(locationid2)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==所属区县==','');
for (i=0;i<onecount3;i++)
{
if (subval3[i][0]==locationid2)
{document.form1.s3.options[document.form1.s3.length]=new Option(subval3[i][2],subval3[i][1]);}
}
}
//-->
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="form1" method="POST" action="a.php">
<tr>
<td width="150">
<select name="s1" onChange="changeselect1(this.value)">
<option>==所属省份==</option>
<?php
$sqlClass1=mysql_query("select * from crm_province order by autoID asc");
$rsClass1=mysql_fetch_array($sqlClass1);
$count1=0;
if($rsClass1!=false)
{
do
{
?>
<option value="<?php echo $rsClass1[autoID];?>"><?php echo $rsClass1[TypeName];?></option>
<?php
$count1++;
}
while($rsClass1=mysql_fetch_array($sqlClass1));
}
?>
</select><font color="#FF0000">*</font></td>
<td width="150"><select name="s2" onChange="changeselect2(this.value)">
<option>==所属市区==</option>
</select><font color="#FF0000">*</font></td>
<td><select name="s3">
<option>==所属区县==</option>
</select><font color="#FF0000">*</font></td>
</tr>
</form>
</table>