In this paper, the CodeIgniter framework is used to obtain the paging data and the total number of bars. Share to everyone for your reference. The implementation methods are as follows:
Generally in the data paging need to get the current page data and total number of pages, the average person is in the model to encapsulate two functions to get the current page of data and data total bar number, business logic similar, feel a little redundant, can be packaged together
Copy Code code as follows:
/**
* Get the paging data and the total number of bars
* @param string @tablename table name
* @param mixed $where conditions
* @param int $limit number of pages per page
* @param int $offset Current page
*
*/
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);
}
I hope this article will help you with the PHP program design based on CodeIgniter framework.