• php简单实现二级联动


    <script type="text/javascript">
    //当第一级选项发生变化的时候跳转
    function jump() {
    location.href='?firstid='+document.getElementById('first').value;
    }
    
    </script>
    <?php
    //连接数据库
    @mysql_connect('localhost','root','');
    mysql_select_db('test');
    mysql_query('set names utf8');
    
    $firstid=isset($_GET['firstid'])?$_GET['firstid']:'';	//获取提交的firstid
    ?>
    <!--获取第一级-->
    <select id='first' onchange='jump()'>
    <option value="">---请选择---</option>
    <?php
    $sql='select * from shoplist where parentid=0';
    $rs=mysql_query($sql);
    while($rows=mysql_fetch_assoc($rs)):
    ?>
    <option value="<?php echo $rows['id']?>" <?php echo $rows['id']==$firstid?'selected':''?>><?php echo $rows['name']?></option>
    <?php
    endwhile;
    ?>
    </select>
    <!--获取第二级-->
    <select id='second'>
    <option value="">---请选择---</option>
    <?php
    $sql="select * from shoplist where parentid=$firstid";
    $rs=mysql_query($sql);
    while($rows=mysql_fetch_assoc($rs)): 
    ?>
    <option value="<?php echo $rows['id']?>"><?php echo $rows['name']?></option>
    <?php endwhile;	?>
    </select>

     结果

  • 相关阅读:
    itertools 迭代
    hmac 算法模块
    hashlib模块
    POJ1066线段交点
    POJ2653判断线段相交
    POJ1556 最短路 + 线段相交问题
    POJ1269求两个直线的关系平行,重合,相交
    计算几何小结1
    计算几何之叉积(外积)得应用
    差分约束系统——你能忍受得糖果数量
  • 原文地址:https://www.cnblogs.com/zxf100/p/6748190.html
Copyright © 2020-2023  润新知