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.

  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


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
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: