Home arrow PHP arrow Page 4 - Paginating Database Records with the Code Igniter PHP Framework

Completing the development of the sample MySQL-driven application - PHP

In the previous tutorials in this nine-part series, we built a simple application with the Code Igniter PHP framework. In this article, the third part of the series, we're going to add some important functionality to this application by using the pager class included with Code Igniter.

  1. Paginating Database Records with the Code Igniter PHP Framework
  2. Retrieving user-related data from a MySQL table
  3. Paging database records with Code Igniter
  4. Completing the development of the sample MySQL-driven application
By: Alejandro Gervasio
Rating: starstarstarstarstar / 21
August 27, 2008

print this article



In the section that you just read, you learned how to use the pagination class included with Code Igniter to display a few paginated rows, which were retrieved from the corresponding ďusersĒ MySQL table, defined earlier.

In this case, though, the term ďdisplayĒ isnít totally correct, since itís necessary to build a view file first, which will actually print this data on the browser. Taking into account this concept, below I listed the signature of the file in question, so you can grasp quickly how it works. Take a look at it, please:



<title><?php echo $title;?></title>



<h1><?php echo $header;?></h1>


<?php foreach($users as $user):?>


<p><?php echo 'Full Name: '.$user['firstname'].' '.$user['lastname'].' Email: '.$user['email'];?></p>


<?php endforeach;?>


<p><?php echo $links;?></p>



If you examine in detail the above view file, youíll have to agree with me that it looks really simple! As show before, the file includes a few echo statements, which are used to display the paged rows and for showing the respective page links.

Asides from listing for you the prior view file, I also included below a couple of illustrative images, which show how the paginated records are displayed on the browser. Here they are:

See how simple it is to paginate database rows with Code Igniter? I bet you do! Indeed, the whole process is reduced to defining a controller that uses its pagination class, and then creating a view file that displays the paged rows. Thatís all.

And now that I mentioned a view file, donít forget to save the previous one to the Code Igniter /system/application/views/ folder, so you can test the complete database-driven application by typing the following URL:

With this final example, Iím wrapping up this tutorial on paginating database records. As usual with many of my articles on PHP development, feel free to tweak all of the code samples shown in this article, so you can acquire a more solid background in using Code Igniter.

Final thoughts

In this third chapter of the series, I demonstrated how easy it is to develop a MySQL-based web application that implements an effective paging mechanism with the Code Igniter PHP framework. Undoubtedly, this particular example demonstrates that a framework can be friendly and powerful at the same time.

In the next installment, Iíll be showing you how to use Code Igniterís validation class along with some helper functions to validate web forms.

Donít miss the next article!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: