Categories
- Ajax (1)
- Bisdak Blogger (1)
- chicks (1)
- Coffee and Paste (1)
- css (5)
- Excel (1)
- General Info (5)
- HTML (1)
- javascript (7)
- more (8)
- MySQL (1)
- pdf (1)
- Photoshop (1)
- PHP (26)
- SEO (1)
- sports (2)
Blog Archive
-
►
2009
(37)
-
►
March
(13)
- strlen vs isset in PHP
- 40 Tips for optimizing your php code
- $HTTP_SERVER_VARS
- Cross browser compatibility test site
- Detecting Mobile Browsers in PHP
- Passing JavaScript variables to PHP
- single-quote( ' ) vs double-quote ( " ) in PHP
- PHP Arrays
- Advantages of Using Functions
- Differences between constants and variables
- $_GET vs $_POST in PHP Forms
- require() vs include() in PHP
- What does !important mean in CSS?
-
►
February
(12)
- Javascript onclick return false does not work in I...
- Coffeeandpase Blogger: A Heavy Downloader
- Where is php.ini?
- Make a face
- Turn your photo into a cartoon
- Retrieving Japanese Text from MySQL using PHP
- CSS Play: Experiments with CSS
- New Online MD5 Hash Cracker!
- PNG Alpha Transparency Fix in IE
- Blogger.com as a website instead of a blog?
- Email address validation using Javascript
- PHPMailer: SMTP Authentication
-
►
March
(13)
-
▼
2008
(14)
-
▼
December
(8)
- Simple php pagination
- Create Image Thumbnails Using PHP and GD
- How to create a dynamic bar graph using PHP and GD...
- How to create a dynamic line graph using PHP and G...
- Simple PHP Image Watermark
- Manny Pacquiao vs Oscar De la Hoya (The Dream Matc...
- Live free streaming!!! Pacquiao vs. De La Hoya
- Javascript equivalent for PHP Functions
-
▼
December
(8)
Blog Roll
- Monkeetech
- Atenean101
- Batangsaag.blogspot.com
- Batangyagit.com
- Bethelo
- beyond-the-norms.org
- Brightartclass.blogspot.com
- Bugits
- Cebu Directories
- Cebudaily.com
- CebuElection
- Cebuheritage.com
- Cebuimage.blogspot.com
- Cebupacificairlines.ph
- Codes Depot
- Dahonglaya.com
- Empressofdrac
- Errol Duazo
- EUTS
- Iamdownloader.com
- Ibeejing
- Icymartagimacruz
- Ie-student
- In-indie.org
- Jerry Gervacio
- Lagahit.com
- Marian Calago
- Marroxas2010
- Mcbilly.com
- Miongandmarquee
- Nurseter
- Pinoyworld.org
- Punkies07
- QueerChef
- rentale
- Sinjin.ph
- softwareportables
- Sunchoke.net
- VeganPrince
- Vera
- Veryducky
- Yugatech
Simple php pagination
What is Pagination?
Think about if you have a mysql table with a thousand rows, and you want to allow the user to browse through the entire table. Displaying all the records in that table in one page would not be a good idea. Instead you should break the table up into smaller parts and let the user navigate through it. This is what pagination is, it allows you to break up large results from a database query, and displays a better navigation for the users.
The following code is a quick and dirty example of php/mysql pagination but if you are familiar with CSS, you can easily style the way the page navigation looks.
<?php
if(!empty($_GET["start"])){
$start = $_GET['start'];// To take care global variable if OFF
}else{
$start = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$limit = 5; // No of records to be shown per page.
$whathis = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// to check the total number of records
$query = mysql_query(" SELECT * FROM <tablename> ") or die (mysql_error());
$total_rows = mysql_num_rows($query);
//select the record with limitation
$query = mysql_query(" SELECT * FROM <tablename> limit $eu, $limit ") or die (mysql_error());
//code for previous
if($back >=0) {
echo "<a href='yourpage.php?start=$back'><font face='Verdana' size='2'>PREV</font></a> ";
}
//code for the number of page with links
$i = 0;
$x = 1;
for($i=0;$i < $total_rows;$i=$i+$limit){
if($i != $eu){
echo "<a href='yourpage.php?start=$i'><font face='Verdana' size='2'>$x</font></a> ";
}else {
echo "<font face='Verdana' size='4' color=red>$x</font>";
} // Current page is not displayed as link and given font color red
$x = $x+1;
}
//code for next
if($whathis < $total_rows) {
echo "<a href='yourpage.php?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";
}
?>
This entry was posted on Sunday, December 14, 2008
and is filed under
more
,
PHP
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.



2 comments:
hello sayo... MERRY XMAS AND HAPPY NEW YEAR!!! mwah! salamat sa pagiging bahagi ng blog ko! magpapahinga muna ako.
-joshy
Looks like everything worked except I have all the rows on every page.
Post a Comment