Page Navigation using CodeIgniter Pagination

In our previous tutorial called “Getting Started with CodeIgniter” I discuss on how to install and configure CodeIgniter. This time I will teach you on how to create a simple “Page Navigation”. This is just a comparison of my previous code found at PHP Page Navigation. You’ll learn the difference between the standard PHP and using a CodeIgniter framework.

Now let us configure the CodeIgniter.

  1. Open autoload.php under Config folder using your PHP Editor.
  2. Open config.php under Config folder.
  3. Open database.php under Config folder.
  4. Open routes.php under Config folder.
  5. Now create a file called pagination.php under controllers folder and paste the following code:
  6. load->helper("url"); $this->load->model("Countries_Model"); $this->load->library("pagination"); } public function index() { $config["base_url"] = base_url() . "pagination"; $config["total_rows"] = $this->Countries_Model->record_count(); $config["per_page"] = 10; $config["uri_segment"] = 2; $this->pagination->initialize($config); $page = ($this->uri->segment(2))? $this->uri->segment(2) : 0; $data["results"] = $this->Countries_Model ->get_countries($config["per_page"], $page); $data["links"] = $this->pagination->create_links(); $this->load->view("pagination", $data); } }
  7. Create a file called countries_model.php under models folder and paste the following code:
  8. db->count_all("tblcountries"); } public function get_countries($limit, $start) { $this->db->limit($limit, $start); $query = $this->db->get("tblcountries"); if ($query->num_rows() > 0) { foreach ($query->result() as $row) { $data[] = $row; } return $data; } return false; } }
  9. Lastly, create a file called pagination.php under views folder and paste the following code:
  10. Pagination with CodeIgniter

    Page Navigation in PHP

    Countries

    Country ID

    Country
    CountryID ?> Country ?>

Now, open your browser and type:
http://localhost/CI/

Note: this assumes that you extract the CodeIgniter framework under www folder and named it as “CI”.

Comments

Submitted byAnonymous (not verified)on Fri, 04/19/2013 - 20:47

its good if i download and used to it
Submitted byespionage (not verified)on Sat, 05/04/2013 - 15:20

sir i just want to ask, if codeigniter works on all php editors such as dreamweaver, notepad ++ etc.?
Submitted byadminon Sat, 05/04/2013 - 22:18

In reply to by espionage (not verified)

Yes...
Submitted byfaizan (not verified)on Sat, 12/07/2013 - 19:19

how to apply css to links appeared in pagination?
Submitted byvladymayr (not verified)on Mon, 03/10/2014 - 20:50

how to insert radio buttons in a table?
Submitted byvladymayr (not verified)on Wed, 03/12/2014 - 12:01

why is it undefined variable: links, results, in filename:pages/pagination.php and invalid argument supplied for foreach()
Submitted byAnonymous (not verified)on Wed, 10/12/2016 - 16:03

An uncaught Exception was encountered Type: RuntimeException Message: Unable to locate the model you have specified: Countries_model Filename: /opt/lampp/htdocs/CI/system/core/Loader.php Line Number: 344
Submitted byRipon Uddin (not verified)on Wed, 11/22/2017 - 19:14

This is really a good start up for life because of this website also. Because we know that Stackoverflow helps us to findout best resource. Also this website inspire a developer to develop more and more skill about programming. Because of this .Website .Thank you so much for create this website.

Add new comment