I have two query results, a list of Courses and a list of user profiles. These queries are not related to each other.
I want to display the courses and user profiles in the same view. How do i set the LIMIT and OFFSET for each of these queries so that pagination works fine?
And what will be the pagination $config value like?
What i tried!
I have a method called tabel_list() in my model which returns the records and the total number of records returned.
For Courses:
$rows = $this->main_model->tabel_list($this->limit , $this->uri->segment(3), $joins, $order_by, $table, $select_fields, $condit, $group_by);
$data['total_rows'] = $rows['rows']['total'];
$records = $rows['list'];
$data['products'] = $records;
For User profiles:
If something is true, retrieve the user profiles as well for the view.
$data['tutors'] = $tutor_records['list'];
$individual_rows = $tutor_records['rows']['total'];
$final_num_rows = $rows['rows']['total'] + $individual_rows;
$data['total_rows'] = $final_num_rows;
The configs:
$config['total_rows'] = $data['total_rows'];
$config['base_url'] = base_url() . "home/courses/";
$config['per_page'] = $this->limit;
$config['uri_segment'] = 3;
Two result sets in one view AND working with one pagination. Help?
So, this is the solution to my problem.
I wanted two sets of results to be in one view. I want 20 records to be displayed in one page. So,
$config['per_page'] = 20
If the user wants just the list of courses, only one query runs, else two query results are to be displayed. What should be the offset of the queries?
Well, a simple conditional check/flag can determine if the user wants two sets of results and if he/she does want two sets of results, divide the current page index by 2. So you will have 10 results of each result set on the page.
if(user wants two sets of results on the same page))
{
$offset = $this->uri->segment(3) / 2;
}
If the user wants just one set of results,
$offset = $this->uri->segment(3);
Now use the limit of 20 and this $offset in your database query.
Hope this helps someone.