首页 > 其他 > 详细

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

时间:2015-05-18 20:47:32      阅读:185      评论:0      收藏:0      [点我收藏+]

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

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);

    }

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!