Welcome Guest, Not a member yet? Register   Sign In
Pagination and HTML Table
#1

[eluser]gregor4711[/eluser]
Hi,
I'm new in codigniter. Great Framework. Regards to the topic I have an understanding issue.

1. Sync the table class and the pagination class the required data by itself, or I have to pic up the page number and filter the result to show only the required data for the actual page with the limit function? Any example aviable for pagination and html table together?

2. I miss the function to change the displayed records per page (like ALL, 10, 20, 50)

Thanks for any help
Gregor
#2

[eluser]Michael Wales[/eluser]
controller:
Code:
class Posts extends Controller {
  
  function show_table($offset = 0, $limit = 10) {
    // Load Pagination and setup options
    $this->load->library('pagination');
    $config['base_url'] = site_url('posts/show_table'); // What will CI use for the page links?
    $config['total_rows'] = $this->db->count_all('posts'); // How many items are we paging through?
    $config['per_page'] = $limit; // How many items per page?
    $this->pagination->initialize($config);

    // Get this page's posts, by using the offset the pagination class
    // is going to pass back to this same method.
    $this->data->posts = $this->db->get('posts', $limit, $offset);
    $this->load->view('posts/list', $this->data);
  }
}

View:
Code:
<table>
&lt;?php foreach ($posts as $p): ?&gt;
  <tr>
    <td>&lt;?php echo $p->title; ?&gt;</td>
    <td class="right">&lt;?php echo date('j M y', strtotime($p->created_on)); ?&gt;</td>
  </tr>
&lt;?php endforeach; ?&gt;
</table>
&lt;!-- The following line will display the page links if they exist.
     It will also automatically "highlight" the current page.
     If you notice the current page not working, check the 'uri_segment' config option. --&gt;
&lt;?php echo $this->pagination->create_links(); ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB