?? setpage.php
字號:
<?PHP
//############################################
// This is a class used to set pages
//
// INSTRUCTIONS:
// 1. Define an object of the class page;
// 2. Call function "SetValue()" , using three parameters to
// tell "how many items there are" , "how many items
// will be showed on the page" and "what's your current
// page". If anyone of them is ignored,their default
// value will be 0 , 10 and 1;
// 3. Call function "limit()", using one parameter to tell
// "your sql sentence".
//
//############################################
/**************************************************************
SAMPLE
$pg = new page;
$db = new mysql;
db->connect();
db->select_db("student");
$res = $db->query("select * from student");
$num = $db->num_rows($res);
$page = $_GET["page"] ? $_GET["page"] : 1;
$pg->SetValue($num,10,$page);
$sql = $pg->limit("select * from student where term = '2004' order by id desc");
$db->query($sql);
$pg->next();
$pg->pre();
echo "共".$pg->GetMax()."頁";
**********************************************************/
class page
{
var $num_per_page; //how many items will be displayed in a page
var $total; //how many items are there to display
var $max_page; //the number of the last page
var $current_page;
var $next_page;
var $pre_page;
//construction function
function page()
{
$this->num_per_page = 10;
$this->total = 0;
$this->max_page = $this->GetMax();
$this->current_page = 1;
$this->next_page = 0;
$this->pre_page = 0;
}
//Set values of member variables
function SetValue($total=0,$npp=10,$current_page=1)
{
$this->total = $total;
$this->num_per_page = $npp;
$this->max_page = $this->GetMax();
if(empty($current_page)) $current_page = 1;
$this->current_page = $current_page;
if($this->current_page<$this->max_page) $this->next_page = $this->current_page +1;
else $this->next_page = 0;
if($this->current_page>1) $this->pre_page = $this->current_page -1;
else $this->pre_page = 0;
}
//Return the LIMIT string in SQL
function limit($sql)
{
$offset = ($this->num_per_page)*($this->current_page - 1);
return $sql." limit ".$offset.",".$this->num_per_page;
}
//Print the link of next page
function next($get="",$text="下一頁",$color1="",$color2="")
{
$link = "<a href='".$_SERVER['PHP_SELF']."?".$get."&page=".$this->next_page."'><font color=".$color1.">".$text."</font></a>";
if($this->next_page)
echo $link;
else
echo "<font color=".$color2.">".$text."</font>";
}
//Print the link of previous page
function pre($get="",$text="上一頁",$color1="",$color2="")
{
$link = "<a href='".$_SERVER['PHP_SELF']."?".$get."&page=".$this->pre_page."'><font color=".$color1.">".$text."</font></a>";
if($this->pre_page)
echo $link;
else
echo "<font color=".$color2.">".$text."</font>";
}
//Get the number of the last page
function GetMax()
{
$max_page = ceil($this->total / $this->num_per_page);
if($max_page==0) $max_page = 1;
return $max_page;
}
function PageClick($get="",$pages=10,$str=" ")
{
if($this->current_page%10==0)$begin=$this->current_page-10+1;
else $begin = $this->current_page-$this->current_page%10+1;
$end = $begin + $pages;
if($begin>10)echo "<a href='".$_SERVER['PHP_SELF']."?$get&page=".($begin-10)."' title='Previous $pages'><</a>".$str;
for($count=$begin;$count<$end&&$count<=$this->max_page;$count++)
{
if($count==$this->current_page)echo $count.$str;
else echo "<a href='".$_SERVER['PHP_SELF']."?$get&page=".$count."'>$count</a>".$str;
}
if($end<=$this->max_page)echo "<a href='".$_SERVER['PHP_SELF']."?$get&page=".($begin+10)."' title='Next $pages'>></a>".$str;
}
}
?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -