⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setpage.php

📁 为我们学校开发的一个住房货币化补贴工作的专题网站
💻 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="&nbsp;")
	{
		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 + -