PHP implements the class of page turn processing
PHP Instance source code: PHP Implementation of the class page turn processing
Class page{
var $CountAll; Total number of records
var $CountPage; Shows the number of records per page
var $Link; Show full Paging information
var $ForPage; Previous page
var $NextPage; Next page
var $FirstPage; First page
var $LastPage; Last page
var $CurrPage; The first few pages
var $PageNum; How many pages are there?
var $Parameter; Parameters
var $LimitNum; Instead of counting all records, it shows some records, such as a total of 100 records, but only the first 50 are displayed.
function Page ($sql, $num =30) {
Initialization, number of statistics records
$this->countpage = $num;
Global $mysql;
$sql = Base64_decode ($sql);
$result = $mysql->query ($sql);
if (0! = $mysql->affectedrows ()) {
$row = $mysql->fetcharray ($result);
$this->countall = $row [0];
}
else{
$this->countall = 0;
}
Print "Total $this->countall
";
}
function Listpage ($sql, $page =0, $sql _all, $other) {
Query, define variables, get data
Global $mysql;
print "SQL SQL
";
if (Isset ($this->limitnum) && $this->countall > $this->limitnum) {
$this->countall = $this->limitnum;
}//Update total number of browsing records
$sql _src = $sql;
if ($page > 0) {
$sql = Base64_decode ($sql);
$sql _all = Base64_decode ($sql _all);
$sql _src = $sql;
//}
Echo $sql;
if ($this->countall% $this->countpage) = = 0)//Statistics total number of pages
$pagecount = (integer) ($this->countall/$this->countpage);
Else
$pagecount = (integer) ($this->countall/$this->countpage) +1;
$this->agenum = $pagecount;
if ($page > $this->agenum)//Set to Maximum page number if page numbers exceed the total number of pages
$page = $this->agenum;
if ($page <= 0)//Set page number to 1 if page number is less than or equal to zero
$page = 1;
if ($this->countall = = 0)
{
$this->currpage = 0;
}else{
$this->currpage = $page;
}
$first _start = ($page-1) * $this->countpage;
$sql = $sql. "Limit". $first _start. ",". $this->countpage;
Print "2sql
";
$result = $mysql->query ($sql);
if (0! = $mysql->affectedrows ()) {
$i = 0;
while ($row = $mysql->fetcharray ($result)) {
$array [$i] = $row;
Print "Name:". $array [$i][name]. "
";
$i + +;
}
}
$sql = Base64_encode ($sql _src);
$sql _all = Base64_encode ($sql _all);
if ($pagecount >1) {
if ($page = = 1) {
$nextpage = $page +1;
$forpage = 1;
$this->link = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
$this->nextpage = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
$this->lastpage = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
}
else if (($page > 1) && ($page < $pagecount)) {
$forpage = $page-1;
$nextpage = $page +1;
$this->link = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
$this->forpage = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
$this->nextpage = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
$this->firstpage = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
$this->lastpage = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
}
else if ($page = $pagecount) {
$forpage = $page-1;
$nextpage = 1;
$this->link = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
$this->firstpage = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
$this->forpage = "Parameter. " &sql_all= ". $sql _all." ". $other. "'" class= "button_a" style= "width:30;height:22";>";
}
}
else{
$this->link = ";
}
return $array;//$array;
}
}
/***************
Examples of Use
Include ("class.config.php");
Include ("class.mysql.php");
Include ("class.page.php");
Global $mysql;
$config = new Config;
$mysql = new Tdatabase ($config);
$query _all = "SELECT count (*) from user";
$page _object = new page ($query _all,20);
New page (' Statistics record count statement ', number of records per page)
if (Empty ($query _page))
$query _sql = "SELECT * from user";
Note that the variable name here must be $query _sql $query _page, because the connection parameter for the next page defaults to Query_sql query_page
$list = $page _object->listpage ($query _sql, $query _page);
Listpage (' No previous part of limit, system automatically according to completion ', view of pages)
$page _object->parameter = ' &action=view ';
This is the URL of the transmission of other parameters, if there is a change in the variable Parameter, the system will automatically fill her back
Show data
for ($i =0; $i < $page _object->countpage; $i + +)
Print $list [$i][id]. " . $list [$i][username]. "
";
The returned data is a two-dimensional hasi (associative) array, one-dimensional is the ID number of the record, the two-dimensional is a hasi (associative) array, and the value identifies a method that uses the name of the field in the database, such as List[0][username].
Show other related data
Echo $page Total _object->countall;//Records
echo $page _object->countpage;//The number of data displayed per page
echo $page _object->link;//Display full paging information
echo $page _object->firstpage;//first page
echo $page _object->nextpage;//next page
echo $page _object->forpage;//PAGE Up
echo $page _object->lastpage;//last page
echo $page _object->currpage;//first page
echo $page _object->pagenum;//How many pages are there?
$mysql->databaseclose ();
****************/
?>