Home arrow PHP arrow Page 2 - Paginating MySQL Data with PHP

Getting Started - PHP

Have a large MySQL dataset that you would like to display on your website, but don't want to bog down your users' connections with large HTML renderings? Try paginating your data.

TABLE OF CONTENTS:
  1. Paginating MySQL Data with PHP
  2. Getting Started
  3. Making a Connection
  4. Limiting the Dataset
  5. Conclusion
By: Adrian Portsmouth
Rating: starstarstarstarstar / 53
March 27, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
So lets get started going through the various parts of the code. At the end I will display it all together and you should be able to read and understand what it is doing.

The first thing to do is set the variables that the script will need in order to work correctly. The variables may change at some point, so we put them at the top of the script where they are easy to find if we need to change them. If they are used multiple times within the script we will only need to edit them in one place.


// Set Script Variables $DB_Host="localhost"; $DB_Name="MyDataBase"; $DB_User="MyUserName"; $DB_Pass="MyPassword"; $Per_Page=10;
As I said these variables will be used in various stages of the script. We will now go through them one by one. $DB_Host should contain the host name where your MySQL resides, in most cases this is 'localhost'. The next three variables are used to connect to your MySQL database; $DB_Name will be the name of the database, $DB_User should contain your MySQL username and $DB_Pass should contain your MySQL password. Finally $Per_Page, this variable defines how many results will be displayed on each page. In this article we are going to display 10 results per page, but you can change this figure to any number that suits your system and layout.

 
 
>>> More PHP Articles          >>> More By Adrian Portsmouth
 

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap

Dev Shed Tutorial Topics: