Welcome Guest, Not a member yet? Register   Sign In
How to make pagination with Multiple Tables
#1

[eluser]Unknown[/eluser]
Hello Sir/Madam,

How can i make pagination with multiple tables? Because i can make with one table.


Best,

Veasna.
#2

[eluser]Jan_1[/eluser]
so you want to have 2 or more tables in a view and every table has a pagination?
Have a try, show us what you're doing and may be make an assumption.
Otherwise someone has to write a hole tutorial to answer your question.
CU
#3

[eluser]umefarooq[/eluser]
there are two solutions to do this if you have two or more tables and they have relations with each other then use sql joins to get your data, get counts and use normal way pagination library,

2nd way if you don't have relation between your tables, get you records from tables and then merge them, then take count and pass to you pagination class, then use array_slice php function will help you to solve you problem. here is little example

Code:
$rows_1 = $this->db->select('*')->from('table1')->get()->result();
  $rows_2 = $this->db->select('*')->from('table2')->get()->result();
  $rows = array_merge($rows_1,$rows_2);
  
  $total_rows = count($rows);
  $limit = 20;
  $uri_segmetn = 3;
  $current_page = $this->uri->segment($uri_segment, 0);

  $config['base_url'] = site_url($uri);
  $config['total_rows'] = $total_rows;
  $config['per_page'] = $limit;
  $config['uri_segment'] = $uri_segment;
  $this->pagination->initialize($config);
  $data['links'] = $this->pagination->create_links()  
  $data['rows'] = array_slice($rows, $current_page , $limit);
  $this->load->view('view',$data);

i hope will help you to solve your problem




Theme © iAndrew 2016 - Forum software by © MyBB