Old 10-16-2004   2 links from elsewhere to this Post. Click to view. #1 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
Pagination tutorial here!

hee,i had gone to many website ralated to PHP,and i found that too many peoples asking about how to pagination in PHP,here i will guide you through it with the easiest way

1.now we begin with this:
PHP Code:
if(!$page)
{
$page=1;

see those code above?it works like:if your page is not set yet,it will set your page to 1,mean page 1.

2.a little matimathicall here:
PHP Code:
$max=5;
$num=$page $max $max;
$totalpage ceil($lines/$max)+1
I will explain it:
+the variable $max is your max result in 1 page
+in the variable $Num,we have to think,example,your page is 2,then the result of $num is 5(so if the page is 3,it will pass 5 results again to go to the 10 result),so in the loop to display data,we will use this
+In variable $totalpage,
--$lines is your line(or row)in your data(hope u know how to speccify this)
--ceil mean Returns the next highest integer value by rounding up value if necessary. The return value of ceil() is still of type float as the value range of float is usually bigger than that of int. ,so it will give $totale page the interger value.

3.the pagination:
PHP Code:
if ($page 1) {
        echo 
"<a href=\"?page=".($page-1)."\">[Prev]</a>&nbsp;\n";
    }
    for(
$i=1$i<$totalpage$i++) {
        if (
$i == $page) {
            echo 
"<b>[$i]&nbsp;</b>\n";
        } else {
            echo 
"<a href=\"?page=".$i."\">[$i]</a>&nbsp;\n";
        }
    }
    if (
$page $totalpage-1) {
        echo 
"<a href=\"?page=".($page+1)."\">[Next]</a>\n";
    } 
It simple to understand,so i wont explain this,(cuz i have to go to school now lolz :P)

4.now u done it,the whole code is here:
PHP Code:
(data display can goes here if u wnat the pagination under the result)
/*==========================Pagination============================*/
if(!$page)
{
$page=1;
}
$max=5;
$num=$page $max $max;
$totalpage ceil($lines/$max)+1;

if (
$page 1) {
        echo 
"<a href=\"?page=".($page-1)."\">[Prev]</a>&nbsp;\n";
    }
    for(
$i=1$i<$totalpage$i++) {
        if (
$i == $page) {
            echo 
"<b>[$i]&nbsp;</b>\n";
        } else {
            echo 
"<a href=\"?page=".$i."\">[$i]</a>&nbsp;\n";
        }
    }
    if (
$page $totalpage-1) {
        echo 
"<a href=\"?page=".($page+1)."\">[Next]</a>\n";
    }

echo 
"<BR>";echo "<a HREF='form.html'>sign!<BR></a>" ;
/*========================end of pagination========================*/
(or data display can goes here
====================
My E is really terrible,so if u dont understand some point,just ask me,i`m willing tp answer you
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://forums.biorust.com/html-php-asp-js/1120-pagination-tutorial-here.html
Posted By For Type Date
building a pagination This thread Refback 08-08-2008 12:32 PM
building a pagination This thread Refback 06-04-2008 07:11 PM


All times are GMT +1. The time now is 03:06 PM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT