Codeigniter框架實現(xiàn)獲取分頁數(shù)據(jù)和總條數(shù)的方法
本文實例講述了Codeigniter框架實現(xiàn)獲取分頁數(shù)據(jù)和總條數(shù)的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
一般在數(shù)據(jù)分頁的時候需要獲取當(dāng)前頁的數(shù)據(jù)和總條數(shù),一般人是在model中封裝兩個函數(shù)分別獲取當(dāng)前頁的數(shù)據(jù)和數(shù)據(jù)總條數(shù),業(yè)務(wù)邏輯類似,感覺有點冗余,可以封裝在一起
* 獲取分頁數(shù)據(jù)及總條數(shù)
* @param string @tablename 表名
* @param mixed $where 條件
* @param int $limit 每頁條數(shù)
* @param int $offset 當(dāng)前頁
*
*/
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);
}
希望本文所述對大家基于Codeigniter框架的PHP程序設(shè)計有所幫助。
相關(guān)文章
php權(quán)限調(diào)整強(qiáng)制用戶退出的解決步驟
這篇文章主要介紹了php權(quán)限調(diào)整強(qiáng)制用戶退出的解決步驟,當(dāng)用戶登錄時,將用戶的登錄狀態(tài)和其他相關(guān)信息存儲在服務(wù)器端,本文結(jié)合實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-09-09Laravel學(xué)習(xí)教程之IOC容器的介紹與用例
最近在學(xué)習(xí)laravel,正好學(xué)習(xí)到了ioc容器,但發(fā)現(xiàn)網(wǎng)上這方面的資料較少,所以將自己學(xué)習(xí)的總結(jié)下,下面這篇文章主要給大家介紹了關(guān)于Laravel學(xué)習(xí)教程之IOC容器的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-08-08php htmlentities()函數(shù)的定義和用法
下面小編就為大家?guī)硪黄猵hp htmlentities()函數(shù)的定義和用法。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05