อยากให้แสดงหน้าละ10ข้อมูล แล้วให้มีการคลิก Next ได้ถ้าต้องการดูข้อมูลหน้าอื่นค่ะ
Tag : - - - -
Date :
4 เม.ย. 2548 12:19:01
By :
TAR
View :
2442
Reply :
3
No. 1
Guest
ต้อง Save เป็น file php ก่อน แล้วทำการ include เข้าไป ตัวอย่างวิธีใช้อยู่ใน code แล้ว ลองดูเผื่อช่วยได้ฮะ
<?php
/******************* Example : Use Pager.Class.php *************************
require_once("Pager.Class.php"); // Instantiate class
$p = new Pager;
$limit = 100; // Show many results per page?
$start = $p->findStart($limit); // Find the start depending on $_GET['page'] (declared if it's null)
// Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query
$count = mysql_num_rows(mysql_query("SELECT field FROM table"));
// Find the number of pages based on $count and $limit
$pages = $p->findPages($count, $limit);
// Now we use the LIMIT clause to grab a range of rows
$result = mysql_query("SELECT * FROM table LIMIT ".$start.", ".$limit);
// Now get the page list and echo it
$pagelist = $p->pageList($_GET['page'], $pages);
echo $pagelist;
// Or you can use a simple "Previous | Next" listing if you don't want the numeric page listing
//$next_prev = $p->nextPrev($_GET['page'], $pages);
//echo $next_prev;
*********************************************************************************/
class Pager
{
/***********************************************************************************
* int findStart (int limit)
* Returns the start offset based on $_GET['page'] and $limit
***********************************************************************************/
function findStart($limit,$page){
/*
if ((!isset($_GET['page'])) || ($_GET['page'] == "1")){
$start = 0;
$_GET['page'] = 1;
} else {
$start = ($_GET['page']-1) * $limit;
}
*/
if ((!isset($page)) || ($page == "1")){
$start = 0;
$page = 1;
} else {
$start = ($page-1) * $limit;
}
return $start;
}
/***********************************************************************************
* int findPages (int count, int limit)
* Returns the number of pages needed based on a count and a limit
***********************************************************************************/
function findPages($count, $limit){
$pages = (($count % $limit) == 0) ? $count / $limit : floor($count / $limit) + 1;
return $pages;
}
/***********************************************************************************
* string pageList (int curpage, int pages)
* Returns a list of pages in the format of "« < [pages] > »"
***********************************************************************************/
function pageList($Language=1,$curpage, $pages,$count,$limit,$PageListRang=0,$First=1,$Previous=1,$PageListAll=1,$Next=1,$Last=1,
$para1="",$paraval1="", $para2="",$paraval2="", $para3="",$paraval3="" ,$para4="",$paraval4="" , $para5="",$paraval5="" ){