Home > Backend Development > PHP Tutorial > php有关问题,你肯定会,帮小弟我这个新手解决一下吧

php有关问题,你肯定会,帮小弟我这个新手解决一下吧

WBOY
Release: 2016-06-13 13:48:25
Original
871 people have browsed it

php问题,你肯定会,帮我这个新手解决一下吧
页面原来显示数据库读取的数据是按照时间来排序的,我想添加两个按钮,一个是按年龄排序,一个是按照时间排序。
我的问题就是怎么一点按年龄排序这个控件就执行“select * from log order by l_age”;
一点按照时间排序就执行“select * from log order by l_time”。用submit或者select的onclick事件都行。或者您有什么更好的办法也行。谢谢了

------解决方案--------------------
表单






构造查询串
$orderkey = isset($_GET['orderkey']) && $_GET['orderkey'] == '按年龄排序' ? 'l_age' :'l_time';
$sql = "select * from log order by $orderkey";


------解决方案--------------------
PHP code
<?php if($_GET['order']=="age"){
    $order="age";    
    }
else{
    $order="l_time";    
    }
$sql="select * from log order by $order";
?>
<a href="?order=age">按年龄排序</a> <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template