|
 |
|
สอบถามเรื่องการแบ่งการแสดงข้อมูลเป็นหน้า จะเขียนยังไงครับ |
|
 |
|
|
 |
 |
|
10 หน้าของคุณนี้หมายถึง 10 row หรือป่าวอ่านแล้วงง
|
 |
 |
 |
 |
Date :
2010-10-18 12:51:22 |
By :
kanchen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา page ปัจจุบัน
เริ่มต้น = ปัจุุบัน - 10 (ถ้าน้อยกว่า 0 ให้ = 0)
สิ้นสุด = ปัจจุบัน + 10 (ถ้ามากกว่ากว่า max ให้ = max)
แล้วเอาค่านี้ไปใช้ใน loop for ครับ
|
 |
 |
 |
 |
Date :
2010-10-18 12:51:50 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้เป็นโค้ดที่ผมเคยเก็บไว้ใช้ชั่วคราวถ้าไงลองเอาไปใช้ แล้ว include เข้ามาครับ
วิธีใช้ก็ประมาณ
Code (PHP)
<?php
echo new pageNavigation('gallery.php',$lastpage); // หน้า 1 | 2 | 3
// ex. <a href='galelry.php?page=1'>1</a>
echo new pageNavigation('gallery.php',$lastpage,array('type'=>'system')); // หน้า 1 | 2 | 3
// ex. <a href='galelry.php?type=system&page=1'>1</a>
echo new pageNavigation('gallery.php',$lastpage,array('type'=>'system','owner'=>'admin')); // หน้า 1 | 2 | 3
// ex. <a href='galelry.php?type=system&owner=admin&page=1'>1</a>
?>
หมายเหตุใช้ชั่วคราวนะครับ เพราะเขียนออกมาเห่ยๆแบบเร่งๆ ส่วน$lastpage คิวรี่แล้วหารเอาครับ
Code (PHP)
<?php
$perPage = 10; //จำนวน record ที่ต้องการให้แสดงต่อหน้า
$count = mysql_num_rows($result);
$lastpage = ceil(count/$perPage);
?>
Code (PHP)
<?php
/*!
* Copyright 2010, Manosate Pipatpatama
***********************************************
* website: http://labworks.in.th/
* facebook: http://facebook.com/manosate/
* twitter: http://twitter.com/manosate
*
*/
class pageNavigation{
private $link;
private $lastPage;
private $attrs;
function __construct($link, $lastPage, $attrs = array()){
$this->link = $link;
$this->lastPage = $lastPage;
$this->attrs = $attrs;
}
function __toString(){
$str = "<div class='page_navigator'>";
$str.= "<strong>หน้า:</strong>";
for($page=1; $page<=$this->lastPage; $page++){
$firstAttr = true;
$str.= " <a href='".$this->link;
foreach($this->attrs as $name => $val){
if($firstAttr){
$firstAttr = false;
$str.= '?';
}
else $str.= '&';
$str.= $name.'='.$val;
}
if($firstAttr){
$firstAttr = false;
$str.= '?';
}
else $str.= '&';
$str.= "page=".$page."'>".$page."</a> ";
if($page<$this->lastPage)
$str.= " | ";
}
$str.= "</div>";
return $str;
}
}
?>
|
ประวัติการแก้ไข 2010-10-18 12:54:38
 |
 |
 |
 |
Date :
2010-10-18 12:52:23 |
By :
manosate |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|