国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > PHP > 正文

Codeigniter框架實(shí)現(xiàn)獲取分頁(yè)數(shù)據(jù)和總條數(shù)的方法

2024-05-04 23:28:39
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
這篇文章主要介紹了Codeigniter框架實(shí)現(xiàn)獲取分頁(yè)數(shù)據(jù)和總條數(shù)的方法,實(shí)現(xiàn)了對(duì)獲取當(dāng)前頁(yè)的數(shù)據(jù)和總條數(shù)方法的封裝,是非常實(shí)用的技巧,需要的朋友可以參考下
 
 

本文實(shí)例講述了Codeigniter框架實(shí)現(xiàn)獲取分頁(yè)數(shù)據(jù)和總條數(shù)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

一般在數(shù)據(jù)分頁(yè)的時(shí)候需要獲取當(dāng)前頁(yè)的數(shù)據(jù)和總條數(shù),一般人是在model中封裝兩個(gè)函數(shù)分別獲取當(dāng)前頁(yè)的數(shù)據(jù)和數(shù)據(jù)總條數(shù),業(yè)務(wù)邏輯類(lèi)似,感覺(jué)有點(diǎn)冗余,可以封裝在一起

復(fù)制代碼代碼如下:
/**
* 獲取分頁(yè)數(shù)據(jù)及總條數(shù)
* @param string @tablename 表名
* @param mixed $where 條件
* @param int $limit 每頁(yè)條數(shù)
* @param int $offset 當(dāng)前頁(yè)

*/
public function get_page_data($tablename, $where, $limit, $offset, $order_by, $db)
{
        if(empty($tablename))
        {
            return FALSE;
        }
        
        $dbhandle = empty($db) ? $this->db : $db;
        
        if($where)
        {
            if(is_array($where))
            {
                $dbhandle->where($where);
            }
            else
            {
                $dbhandle->where($where, NULL, false);
            }
        }
        
        $db = clone($dbhandle);
        $total = $dbhandle->count_all_results($tablename);
        
        if($limit)
        {
            $db->limit($limit);
        }
        
        if($offset)
        {
            $db->offset($offset);
        }
        
        if($order_by)
        {
            $db->order_by($order_by);
        }
        
        $data = $db->get($tablename)->result_array();
        
        return array('total' => $total, 'data' => $data);
}

 

希望本文所述對(duì)大家基于Codeigniter框架的PHP程序設(shè)計(jì)有所幫助。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁城县| 上栗县| 仪征市| 祁东县| 大英县| 济宁市| 桓台县| 镇巴县| 凯里市| 定西市| 石狮市| 安顺市| 兰西县| 五常市| 容城县| 平泉县| 资兴市| 苏尼特左旗| 广平县| 昭觉县| 诸城市| 临桂县| 绥化市| 商都县| 田东县| 横峰县| 聂荣县| 乌鲁木齐县| 安陆市| 延安市| 道真| 泾源县| 桦川县| 唐山市| 澄城县| 淅川县| 宜宾县| 德令哈市| 祁门县| 琼结县| 盐边县|