牛骨文教育服务平台(让学习变的简单)
博文笔记

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

创建时间:2007-11-06 投稿人: 浏览次数:6745

<!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> 

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。