码迷,mamicode.com
首页 > 其他好文 > 详细

更简单、更安全的查询方法

时间:2015-05-18 20:48:26      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:select   安全   

//另一种更安全的方法,且解决了查询,分页的问题,以后都应该用这种方法来做

publicfunction manage($n) {

        $tab = M($n);

        $Bigtitle = I(‘Bigtitle‘);

        $Publishtime = I(‘Publishtime‘);

        $page = isset($_POST[‘page‘]) ?intval($_POST[‘page‘]) : 1;

        $rows = isset($_POST[‘rows‘]) ?intval($_POST[‘rows‘]) : 10;

        $offset = ($page - 1) * $rows;

        $sql[‘Lixiao‘] = ‘‘;

        $sql[‘SchoolID‘] ="$_SESSION[SchoolID]";

        if ($Bigtitle != ‘‘) {

            $sql[‘Bigtitle‘] ="$Bigtitle";

        }

        if ($Publishtime != ‘‘) {

            $sql[‘Publishtime‘] ="$Publishtime";

        }

        $sql[‘_logic‘] = ‘AND‘;

        $total =$tab->where($sql)->count();

        $rs =$tab->where($sql)->limit($offset, $rows)->select();

        if (!isset($rs)) {

            $json->total = 0;

            $json->rows = array();

        } else {

            $json->total = $total;

            $json->rows = $rs;

        }

        $this->ajaxReturn($json);

    }

更简单、更安全的查询方法

标签:select   安全   

原文地址:http://blog.csdn.net/xiesumin/article/details/45826675

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!