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!
blog comments powered by Disqus |
|
|
|
|
|
|
|