亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ThinkPHP使用心得分享-分頁類Page的用法

 更新時間:2014年05月15日 09:50:26   作者:  
ThinkPHP中的Page類能輕松實現(xiàn)查詢內(nèi)容分頁的實現(xiàn),本文小總結(jié)了一下關(guān)于學習過程中對Page類的使用方法。

ThinkPHP中的Page類在ThinkPHP/Extend/Library/ORG/Util/Page.class.php中,所以使用前要引入Page類:

復制代碼 代碼如下:

import('ORG.Util.Page'); //Page類的引入
$db = M('abc');//實例化數(shù)據(jù)表abc
$where = array(
'id'=>'2';
);//條件語句$where,例表中字段id的值為2
$count = $db->where($where)->count();//獲取符合條件的數(shù)據(jù)總數(shù)count
$page = new Page($count, 10);//實例化page類,傳入數(shù)據(jù)總數(shù)和每頁顯示10條內(nèi)容
$limit = $page->firstRow . ',' . $page->listRows;//每頁的數(shù)據(jù)數(shù)和內(nèi)容$limit
$result =$db->where($where))->limit($limit)->select();//分頁查詢結(jié)果
$this->result = $result;//賦值
$this->show = $page->show();//獲取分頁的底部信息

以上代碼是分頁類實現(xiàn)的基本語句,當然喜歡使用原生sql語句的朋友也可以配合原生sql語句實現(xiàn)查詢分頁:

復制代碼 代碼如下:

        import('ORG.Util.Page'); //Page類的引入
        $db = M('abc');//實例化數(shù)據(jù)表abc
        $where = array(
           'id'=>'2';
        );//條件語句$where,例表中字段id的值為2
        $count = $db->where($where)->count();//獲取符合條件的數(shù)據(jù)總數(shù)count
        $page = new Page($count, 10);//實例化page類,傳入數(shù)據(jù)總數(shù)和每頁顯示10條內(nèi)容
        $Modle = new Model();//實例化新數(shù)據(jù)模型
        $sql = 'select id,name from abc where '.$where.' limit '.$page->firstRow.','.$page->listRows;//sql語句
        $result = $Modle->query($sql);//執(zhí)行sql語句
        $this->result = $result
        $this->show=$page->show();

當然,分布查詢獲取的內(nèi)容也可以先對查詢完的數(shù)據(jù)進行處理再賦值,比如

復制代碼 代碼如下:

     ...

    $result =$db->where($where))->limit($limit)->select();//分頁查詢結(jié)果
    $res = abc($result);//abc方法(自定義方法或php函數(shù))對結(jié)果$result進行數(shù)據(jù)排序或重組處理等
    $this->result = $res;//賦值

相關(guān)文章

最新評論