PHP code
1 | $config['base_url'] = "http://localhost/~yannick/pagination/"; |
PHP code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | class Books extends Controller { function __construct() { parent::Controller(); $this->load->helper('url'); $this->load->database(); } function index() { // load pagination class $this->load->library('pagination'); $config['base_url'] = base_url().'index.php/books/index/'; $config['total_rows'] = $this->db->count_all('christian_books'); $config['per_page'] = '5'; $config['full_tag_open'] = '<p>'; $config['full_tag_close'] = '</p>'; $this->pagination->initialize($config); //load the model and get results $this->load->model('books_model'); $data['results'] = $this->books_model->get_books($config['per_page'],$this->uri->segment(3)); // load the HTML Table Class $this->load->library('table'); $this->table->set_heading('ID', 'Title', 'Author', 'Description'); // load the view $this->load->view('books_view', $data); } } |
PHP code
1 | $config['base_url'] = base_url().'index.php/books/index/'; |
PHP code
1 | $config['total_rows'] = $this->db->count_all('christian_books'); |
PHP code
1 | $this->table->set_heading('ID', 'Title', 'Author', 'Description'); |
PHP code
1 2 3 4 5 6 7 8 9 10 | class books_model extends Model { function __construct(){ parent::Model(); } function get_books($num, $offset) { $query = $this->db->get('christian_books', $num, $offset); return $query; } } |
PHP code
1 | $query = $this->db->get('christian_books', $num, $offset); |
SQL code
1 | SELECT * FROM christian_books LIMIT 10, 5 |
PHP code
1 2 3 4 5 6 7 8 9 10 11 12 13 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us"> <head> <meta http-equiv="content-type" c /> <link rel="stylesheet" href='<?php echo base_url(); ?>css/main.css' type="text/css" media="screen, projection" /> <title>CodeIgniter Pagination Tutorial</title> </head> <body> <h1>Christian Books</h1> <?php echo $this->table->generate($results); ?> <?php echo $this->pagination->create_links(); ?> </body> </html> |
PHP code
1 | $this->table->generate($results); |
PHP code
1 | $this->pagination->create_links(); |