0

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 Iget(). 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;

1 Answer 1

2

You need to write another query for getting number of rows (without limit). It should fix your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok... I just figured there might be a simpler / cleaner way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.