您的位置:首页 > 编程语言 > PHP开发

php 实现两个select下拉框的数据联动

2007-11-06 12:36 656 查看
<!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>
<title>role perm modify</title>
<script language="javascript">
function getRole(){
document.role_perm_mod.action="";
document.role_perm_mod.submit();
}
</script>
</head>

<?php
$access_id = "root";
$access_pwd = "831025";
$db_name = "inv";
@ $db = mysql_connect('localhost', $access_id, $access_pwd) or
die("Could not connect to database. Please contact with IT supporting team ASAP.");
mysql_query("SET NAMES 'GBK'");
mysql_select_db($db_name);
?>

<body>
<form name="myform" method="post" action="" >
<table cellpadding="0" cellspacing="1">
<tr><th>Plant:</th>
<td><select name="role_plant" onchange="javascript:getRole()">
<?php
echo '<option value="0">---Please Select---';
$plants_sql = "SELECT plant_id,plant_desc FROM plant WHERE plant_act = '1' ";
$plants_res = mysql_query($plants_sql);

$plant_sql = "SELECT plant_id,plant_desc FROM plant WHERE plant_id='".$_POST['role_plant']."' ";
$plant_res = mysql_query($plant_sql);

$plant_row = mysql_fetch_array($plant_res);

while($plants_row = mysql_fetch_array($plants_res)){
if ($plant_row['plant_id'] == $plants_row['plant_id']){
echo '<option value="'.$plants_row['plant_id'].'" selected > '.$plants_row['plant_id'].' - '.$plants_row['plant_desc'];
}else{
echo '<option value="'.$plants_row['plant_id'].'" > '.$plants_row['plant_id'].' - '.$plants_row['plant_desc'];
}
}
?>
</select>
</td>
</tr>

<tr><th>Role:</th>
<td><select name="role_id">
<?php
echo'<option value="0">---Please Select---';
$roles_sql = "SELECT * FROM sys_role WHERE role_plant='".$_POST['role_plant']."' and role_act='1'";
$roles_res = mysql_query($roles_sql);

$role_sql = "SELECT * FROM sys_role WHERE role_id='".$_POST['role_id']."' and role_act='1' ";
$role_res = mysql_query($role_sql);

$role_row = mysql_fetch_array($role_res);

while($roles_row=mysql_fetch_array($roles_res)){
if($role_row['role_id']==$roles_row['role_id']){
echo "<option value=".$roles_row['role_id']." selected>".$roles_row['role_id']." - ".$roles_row['role_name'];
}else{
echo "<option value=".$roles_row['role_id'].">".$roles_row['role_id']." - ".$roles_row['role_name'];
}
}
?>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: