Paginating Database Records with the Code Igniter PHP Framework - Completing the development of the sample MySQL-driven application (
Page 4 of 4 )
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:
<html>
<head>
<title><?php echo $title;?></title>
</head>
<body>
<h1><?php echo $header;?></h1>
<ul>
<?php foreach($users as $user):?>
<li>
<p><?php echo 'Full Name: '.$user['firstname'].' '.$user['lastname'].' Email: '.$user['email'];?></p>
</li>
<?php endforeach;?>
</ul>
<p><?php echo $links;?></p>
</body>
</html>
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:
http://127.0.0.1/codeigniter/index.php/users/display
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!
| | Discuss Paginating Database Records with the Code Igniter PHP Framework | | | | | | | In this third chapter of the series, you’ll learn how to enhance the MySQL-driven... | | | | | | Hello, first of all congrats for the tutorial, it's very good.
As far as i know,... | | | | | | Thanks for the kind words on my CI article. Yes, CI has some specific rules that... | | | | | | I saw these topics before posting my comment here, thanks... I was looking again the... | | | | | | Thanks for the comments on my article on CI. It’s good to know the previous posts... | | | | | | this will show an error saying:
-----------------
Cannot redeclare class... | | | | | | Thanks for catching that bug. I know that can't be done. In fact, I just discovered... | | | | | | Hi I have seen your code and its very much useful but when I start using the code... | | | | | | Hi R.S.Srikanth,
Thanks for the comments and it’s glad to know my article has... | | | | | | Dear Alejandro Gervasio,
If I want to add one more record at the end of... | | | | | | Hi again Sayed,
Regarding your question, first of naturally you'll have to add a... | | | | | | >>> Post your comment now! | | | | | |
|
 |