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

<!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" οnchange="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> 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值