<?php session_start(); include("conn/conn.php");
//有值传过来就建session
if($_GET[pid]!=""){ $_SESSION["pid"]=$_GET[pid]; }
if($_GET[cid]!=""){ $_SESSION["cid"]=$_GET[cid]; }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>级联菜单 </title>
<style type="text/css">
<!--
.STYLE1 {font-size: 13px}
.STYLE2 {font-size: 14px}
-->
</style>
</head>
<script language="javascript">
//两个跳转的,不用说了吧
function selectcity(x){
if(x!="请选择"){
window.location.href='index.php?pid='+x;
}
}
function selecttown(x){
if(x!="请选择") {
window.location.href='index.php?cid='+x+"&pid="+form1.tb_carte.value;
}
}
</script>
<body>
<form name="form1">
<table width="300" border="0" cellpadding="0" cellspacing="0" background="images/ddd.JPG">
<tr align="center">
<td height="30" colspan="2" nowrap> <span class="STYLE2">级联菜单的应用 </span> </td>
</tr>
<tr align="center">
<td width="120" height="23" nowrap> <span class="STYLE1">省级名称: </span> </td>
<td width="180" align="left" nowrap> <select name="tb_carte" onChange="selectcity(this.value);" >
<option value="请选择"> 请选择 </option>
<?php
//查询输出省
$query=mysql_query("select * from tb_carte");
$myrow=mysql_fetch_array($query);
if($query==true){
do{
?>
<option value=" <?php echo $myrow[id];?>"
<?php
if($_SESSION["pid"]!="") {
if($_SESSION["pid"]==$myrow[id]){
echo "selected=\"selected\"";
}
}?> > <?php echo $myrow[name];?> </option>
<?php
}while($myrow=mysql_fetch_array($query));
}?>
</select> </td>
</tr>
<tr align="center">
<td height="23" nowrap class="STYLE1">市级名称: </td>
<td align="left" nowrap>
//查询输出市
<?php if($_GET[pid]!="") { ?>
<select name="tb_carte1" onChange="selecttown(this.value);">
<option value="请选择" selected="selected"> 请选择 </option>
<?php $query=mysql_query("select * from tb_carte1 where pid='".$_GET[pid]."'");
if($query==true){
while($myrow1=mysql_fetch_array($query)){ ?>
<option value=" <?php echo $myrow1[id];?>"
<?php
if($_SESSION["cid"]!=""){
if($_SESSION["cid"]==$myrow1[id]){
echo "selected=\"selected\"";
}
}?>> <?php echo $myrow1[name1];?> </option>
<?php }}?>
</select>
<?php } ?> </td>
</tr>
<tr align="center">
<td height="23" nowrap class="STYLE1">县/镇级名称: </td>
<td align="left" nowrap>
//查询输出县
<?php if($_GET[cid]!=""){ ?>
<select name="tb_carte1">
<?php
$query=mysql_query("select * from tb_carte2 where cid='".$_GET[cid]."'");
if($query==true){
while($myrow1=mysql_fetch_array($query)){ ?>
<option value=" <?php echo $myrow1[id];?>"> <?php echo $myrow1[name2];?> </option>
<?php }}?>
</select>
<?php } ?> </td>
</tr>
</table>
</form>
</body>
</html>
----conn.php----(这个不用解释)
<?php
$id=mysql_connect("localhost","root","")or dir('连接失败:' . mysql_error());
if(mysql_select_db("cjmp",$id))
echo "";
else
echo ('连接失败:' . mysql_error());
mysql_query("set names gb2312");
?>
tb_carte
id
nametb_carte1
id
pid(tb_carte的id)
nametb_carte2
id
cid(tb_carte1的id)
name
楼主肯定不是做技术的!!!!解释这种代码,我都觉得……
//有值传过来就建session
if($_GET[pid]!=""){ $_SESSION["pid"]=$_GET[pid]; }
if($_GET[cid]!=""){ $_SESSION["cid"]=$_GET[cid]; }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>级联菜单 </title>
<style type="text/css">
<!--
.STYLE1 {font-size: 13px}
.STYLE2 {font-size: 14px}
-->
</style>
</head>
<script language="javascript">
//两个跳转的,不用说了吧
function selectcity(x){
if(x!="请选择"){
window.location.href='index.php?pid='+x;
}
}
function selecttown(x){
if(x!="请选择") {
window.location.href='index.php?cid='+x+"&pid="+form1.tb_carte.value;
}
}
</script>
<body>
<form name="form1">
<table width="300" border="0" cellpadding="0" cellspacing="0" background="images/ddd.JPG">
<tr align="center">
<td height="30" colspan="2" nowrap> <span class="STYLE2">级联菜单的应用 </span> </td>
</tr>
<tr align="center">
<td width="120" height="23" nowrap> <span class="STYLE1">省级名称: </span> </td>
<td width="180" align="left" nowrap> <select name="tb_carte" onChange="selectcity(this.value);" >
<option value="请选择"> 请选择 </option>
<?php
//查询输出省
$query=mysql_query("select * from tb_carte");
$myrow=mysql_fetch_array($query);
if($query==true){
do{
?>
<option value=" <?php echo $myrow[id];?>"
<?php
if($_SESSION["pid"]!="") {
if($_SESSION["pid"]==$myrow[id]){
echo "selected=\"selected\"";
}
}?> > <?php echo $myrow[name];?> </option>
<?php
}while($myrow=mysql_fetch_array($query));
}?>
</select> </td>
</tr>
<tr align="center">
<td height="23" nowrap class="STYLE1">市级名称: </td>
<td align="left" nowrap>
//查询输出市
<?php if($_GET[pid]!="") { ?>
<select name="tb_carte1" onChange="selecttown(this.value);">
<option value="请选择" selected="selected"> 请选择 </option>
<?php $query=mysql_query("select * from tb_carte1 where pid='".$_GET[pid]."'");
if($query==true){
while($myrow1=mysql_fetch_array($query)){ ?>
<option value=" <?php echo $myrow1[id];?>"
<?php
if($_SESSION["cid"]!=""){
if($_SESSION["cid"]==$myrow1[id]){
echo "selected=\"selected\"";
}
}?>> <?php echo $myrow1[name1];?> </option>
<?php }}?>
</select>
<?php } ?> </td>
</tr>
<tr align="center">
<td height="23" nowrap class="STYLE1">县/镇级名称: </td>
<td align="left" nowrap>
//查询输出县
<?php if($_GET[cid]!=""){ ?>
<select name="tb_carte1">
<?php
$query=mysql_query("select * from tb_carte2 where cid='".$_GET[cid]."'");
if($query==true){
while($myrow1=mysql_fetch_array($query)){ ?>
<option value=" <?php echo $myrow1[id];?>"> <?php echo $myrow1[name2];?> </option>
<?php }}?>
</select>
<?php } ?> </td>
</tr>
</table>
</form>
</body>
</html>
----conn.php----(这个不用解释)
<?php
$id=mysql_connect("localhost","root","")or dir('连接失败:' . mysql_error());
if(mysql_select_db("cjmp",$id))
echo "";
else
echo ('连接失败:' . mysql_error());
mysql_query("set names gb2312");
?>
tb_carte
id
nametb_carte1
id
pid(tb_carte的id)
nametb_carte2
id
cid(tb_carte1的id)
name
楼主肯定不是做技术的!!!!解释这种代码,我都觉得……
楼主【baofengyue】截止到2008-06-26 17:04:50的历史汇总数据(不包括此帖):
发帖数:0 发帖分:0
结贴数:0 结贴分:0
未结数:0 未结分:0
结贴率:-------------------结分率:-------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
<?php session_start(); /* 启动会话 */
include("conn/conn.php"); /* 包含外部文件,应该是数据库连接 */
if($_GET[pid]!="") /* 获取以GET方式提交的表单数据,如果不为假,就设置会话 */ { $_SESSION["pid"]=$_GET[pid]; }
if($_GET[cid]!="") /* 获取以GET方式提交的表单数据,如果不为假,就设置会话 */ { $_SESSION["cid"]=$_GET[cid]; }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>级联菜单 </title>
<style type="text/css">
<!--
.STYLE1 {font-size: 13px}
.STYLE2 {font-size: 14px}
-->
</style>
</head>
<script language="javascript">
//两个跳转的,不用说了吧
function selectcity(x){
if(x!="请选择"){
window.location.href='index.php?pid='+x;
}
}
function selecttown(x){
if(x!="请选择") {
window.location.href='index.php?cid='+x+"&pid="+form1.tb_carte.value;
}
}
</script>
<body>
<form name="form1">
<table width="300" border="0" cellpadding="0" cellspacing="0" background="images/ddd.JPG">
<tr align="center">
<td height="30" colspan="2" nowrap> <span class="STYLE2">级联菜单的应用 </span> </td>
</tr>
<tr align="center">
<td width="120" height="23" nowrap> <span class="STYLE1">省级名称: </span> </td>
<td width="180" align="left" nowrap> <select name="tb_carte" onChange="selectcity(this.value);" >
<option value="请选择"> 请选择 </option>
<?php
//查询输出省
$query=mysql_query("select * from tb_carte"); /* 查询 tb_carte 表的所有数据 */
$myrow=mysql_fetch_array($query); /* 根据查询结果生成数组 */
if($query==true){ /* 如果查询成功 */
do{ /* do while 循环 */
?>
<option value=" <?php echo $myrow[id]; ?>" /* 输出数组$myrow[id]的值,$myrow为结果生成的数组,id为数据表tb_carte的字段 */
<?php
if($_SESSION["pid"]!="") { /* 判断$_SESSION["pid"]的值,如果不为空 */ if($_SESSION["pid"]==$myrow[id]){ /* 设置$_SESSION["pid"]的值为$myrow[id] */ echo "selected=\"selected\"";
}
}?> > <?php echo $myrow[name];?> </option> /* 输出数组$myrow[name]的值,$myrow为结果生成的数组,name为数据表tb_carte的字段 */
<?php
}while($myrow=mysql_fetch_array($query)); /* 循环把结果生成数组 */ }?> </select> </td>
</tr>
<tr align="center">
<td height="23" nowrap class="STYLE1">市级名称: </td>
<td align="left" nowrap>
//查询输出市 <?php if($_GET[pid]!="") { ?> /* 如果$_GET[pid]的值不为空 */
<select name="tb_carte1" onChange="selecttown(this.value);">
<option value="请选择" selected="selected"> 请选择 </option> <?php $query=mysql_query("select * from tb_carte1 where pid='".$_GET[pid]."'"); /* 查询tb_carte1表 */
if($query==true){ /* 如果查询成功 */
while($myrow1=mysql_fetch_array($query)){ ?> /* while循环把结果生成数组 */
<option value=" <?php echo $myrow1[id];?>" /* 输出$myrow1[id] */
<?php
if($_SESSION["cid"]!=""){ /* 判断$_SESSION["cid"]的值,如果不为空 */
if($_SESSION["cid"]==$myrow1[id]){ /* 设置$_SESSION["cid"]的值为$myrow1[id] */
echo "selected=\"selected\"";
}
}?>> <?php echo $myrow1[name1];?> </option> /* 输出数组$myrow1[name1]的值,$myrow1为结果生成的数组,name1为数据表tb_carte1的字段 */
<?php }}?>
</select>
<?php } ?> </td>
</tr>
<tr align="center">
<td height="23" nowrap class="STYLE1">县/镇级名称: </td>
<td align="left" nowrap>
//查询输出县
<?php if($_GET[cid]!=""){ ?>
<select name="tb_carte1">
<?php
$query=mysql_query("select * from tb_carte2 where cid='".$_GET[cid]."'"); /* 查询tb_carte2表 */
if($query==true){
while($myrow1=mysql_fetch_array($query)){ ?> /* while循环把结果生成数组 */
<option value=" <?php echo $myrow1[id];?>">/* 输出数组$myrow1[id]的值 */
<?php echo $myrow1[name2];?>/* 输出数组$myrow1[name2]的值 */ </option>
<?php }}?>
</select>
<?php } ?> </td>
</tr>
</table>
</form>
</body>
</html>
----conn.php----(这个不用解释)
<?php
$id=mysql_connect("localhost","root","")or dir('连接失败:' . mysql_error());
if(mysql_select_db("cjmp",$id))
echo "";
else
echo ('连接失败:' . mysql_error());
mysql_query("set names gb2312");
?>