I'm having a really hard time writing this query and getting it to work right with pagination. The query itself is working perfectly. The problem is with $query_count
, which is being passed to the controller to handle pagination.
$query_count
should equal the total number of rows returned by the query, but right now it is being limited to 10 because I am setting a limit when I get()
. How can I pass the limit and offset to the query, but still get the total row count from $query
?
// Build query result for active projects
if ( !empty($campus) && $campus != 'all-campuses' ) {
$this->db->where('campus', $campus);
}
if ( !empty($type) && $type != 'all-types' ) {
$this->db->where('type', $type);
}
if ( !empty($talent) && $talent != 'all-talent' ) {
$this->db->like('talent', $talent);
}
if ( !empty($keyword) ) {
$this->db->like('title', $keyword);
}
$this->db->where('active', true);
$this->db->order_by("date_created", "desc");
$query = $this->db->get('projects', 10, $data['offset']);
$the_rows = $query->result_array();
$query_count = $query->num_rows();
$query_meta['count'] = $query_count;
You need to write another query for getting number of rows (without limit). It should fix your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.