PHP MySQL Paging implementation Code _php tutorial

Source: Internet
Author: User
Tags mysql tutorial php mysql
This is a relatively perfect paging class, support form input jump, also support select Jump paging, but also support on 10 pages, the next 10 page offset paging OH. */

This is a relatively perfect paging class, support form input jump, also support select Jump paging, but also support on 10 pages, the next 10 page offset paging OH.
*/

Class Wind_page
{
var $page;
Now page
var $total;
Record total number of bars
var $totalpage;
Total Page Tree
var $pagesize;
Show number of bars per page
var $offset;
Offset amount
var $result;
Record Collection
var $thispage;
Total number of records//records total number of records//record total number of bars
var $link;
Connect (record $_get variable)
var $bar _mun;
Number of pages displayed in bar
var $starttime;
Start time
var $bar _last;
Page duration of the navigation bar
var $bar _mid;
Navigation Bar Middle Page
var $minpage;
Navigation bar min page
var $maxpage;
Navigation bar Max Page
var $key;
Identify paging (used and differentiated for multiple pagination of a page)
var $style;
The style of the output
var $pre _page_char;
Previous page
var $pre _page_image;
Previous page graphic
var $pre _page_char_color;
Previous page Font Color
var $next _page_char;
Next page
var $next _page_image;
Next page graphic
var $next _page_char_color;
Next page Font Color
var $pre _groud_char;
Upper Middle Page
var $pre _groud_char_color;
Upper middle page Digital body color
var $next _groud_char;
Lower Middle Page
var $next _groud_char_color;
Lower middle page Digital body color
var $first _page_char;
Home
var $first _page_char_color;
Home Font Color
var $last _page_char;
Last
var $last _page_char_color;
Last Font Color
var $html _page_val;
The current page number value of the HTML

function Wind_page ($sql, $pagesize = A, $bar _mun = ten, $style = 1, $this _page = 1, $html _page_val=1, $key = "")//Constructor ()
{
$this->starttime = Microtime ();
$this->pagesize = $pagesize;
Show number of bars per page
$this->key = Trim ($key);
$this->bar_mun = $bar _mun;
$this->style = $style;
$this->html_page_val = $html _page_val;
The current page number value of the HTML
$this->bar_last = $bar _mun-1;
$this->bar_mid = Floor ($bar _MUN/2);
$this->sql = $sql;
$result = MySQL Tutorial _query ($this->sql);
$this->total = mysql_num_rows ($result);
Record total number of bars
$this->totalpage = ceil ($this->total/$this->pagesize);
Total pages
$this->page = ceil ($_get[$this->key. " Page "]);
$this->page = $this _page;
Now page
if ($this->page = = "" | | $this->page < 1 | | !is_numeric ($this->page)) $this->page = 1;
$this->page = min ($this->page, $this->totalpage);
$this->thispage = $this->pagesize;
if ($this->page * $this->pagesize > $this->total) {
$this->thispage = $this->total-($this->page-1) * $this->pagesize;
};
$this->sql. = "Limit". ($this->pagesize * ($this->page-1)). ",". $this->pagesize;
Number of bars to start reading
echo "
";
$this->result = mysql_query ($this->sql);
$this->getvar ();

$this->pre_page_char = "Previous page";
$this->pre_page_image = "";
$this->next_page_char = "Next page";
$this->next_page_image = "";
$this->pre_groud_char = "previous Group";
$this->next_groud_char = "Next Group";

}

function GetVar ()//Gets other get variables except page
{
$this->link = "";
foreach ($_get as $key = = $vaule) {
if (Strtolower ($key)!== $this->key. " Page ") $this->link. =" & $key = $vaule ";
}
}

function Pre_page ($color = "#909090", $sign =0)//prev
{
if ($this->page > 1) {
Return "page-1)." HTML "class=" AB ">pre_page_char_color." > ". $this->pre_page_char.";
} else
{
Return "". $this->pre_page_char. ";
}

}

function Next_page ($color = "#909090", $sign =0)//Next
{
if ($this->page < $this->totalpage) {

Return "page+1)." HTML "class=" AB ">". $this->next_page_char. "";

} else {

Return "". $this->next_page_char. ";
}
}

function Pre_groud ($char = "<<", $color = "#909090")//previous Group
{
if ($this->page <= ($this->bar_mid+1)) {
Return "". $this->pre_groud_char. ";
return $this->pre_groud_char;
} else {
$pre _gpage = ($this->page-$this->bar_mid < 0)? 1:
$this->page-$this->bar_mid;
Return "". $this->pre_groud_char. ";
}
}

function Next_groud ($char = ">>", $color = "#909090")//Next Group
{
if ($this->totalpage-$this->page) <= ($this->bar_mid-1)) {
Return "". $this->next_groud_char. ";
} else {
$next _gpage = ($this->page+ $this->bar_mid < $this->totalpage)? $this->page+ $this->bar_mid:
$this->totalpage;
Return "". $this->next_groud_char. ";
}
}

function mun ($lcolor = "#ff6633", $acolor = "#ff6633", $left = "", $right = "")//Digital navigation bar
{
$link = "";
$this->minpage = ($this->page-$this->bar_mid < 1)? 1: ($this->page-$this->bar_mid);
$this->maxpage = $this->minpage+ $this->bar_last;
if ($this->maxpage > $this->totalpage) {
$this->maxpage = $this->totalpage;
$this->minpage = ($this->maxpage-$this->bar_last < 1)? 1: $this->maxpage-$this->bar_last;
}
for ($i = $this->minpage; $i <= $this->maxpage; $i + +)
{
/* Loop Output page number */
$i = sprintf ("%02d", $i);
Less than two bits of the front complement 0
$char = $left. $i. $right;
Narrow the left and right sides of the navigation bar
if ($i = = $this->page)
{
/* If the current page is not linked */
$link. = "". $char. "";
}
Else
{
$link. = "key." Page= ". $i. $this->link." > ". $char.";
$link. = "". $char. "";
The key is to add $link to the new data.
}
}
echo "
";
return $link;
}


function Jump_bar ($class = "Jump_bar")//pull-down jump
{
$link = ""; for ($i = $this->minpage; $i <= $this->maxpage; $i + +) {if ($i <) $i = "0". $i;//define the selection of no more than 10 if ($this->page = = $i) {/* If it is the current page number, select */$link. = "Section ". $i." Page "; } else {$link. = "Section ". $i." Page "; }} $link. = "";
return $link;
}

function Mun_bar ()//entire digital navigation bar [<<][<][01][02][03][04][05][06][07][08][09][10][>][>>]
{
return $this->first_groud (). $this->pre_groud (). $this->pre_page (). $this->mun (). $this->next_page (). $this->next_groud (). $this->last_groud ();
return $this->pre_groud (). " ". $this->pre_page (). $this->mun (). $this->next_page ()." ". $this->next_groud ();
}
function Page_button ()
{//whole digital navigation bar [<][01][02][03][04][05][06][07][08][09][10][>]
return $this->first_groud (). $this->pre_groud (). $this->pre_page (). $this->mun (). $this->next_page (). $this->next_groud (). $this->last_groud ();
return $this->pre_page (' #909090 ', 1). $this->mun (). $this->next_page (' #909090 ', 1);
}

function Total_bar ($coloro = "#000000", $colorn = "red")//Statistics page: 1/4310 per page: 20 Total: 4310 pages page: 20
{
Return "page: $this->page/$this->totalpage per page: $this->pagesize total: $this->totalpage page This page: $this->thispage" ;
}

Entire navigation bar
Page: 1/4310 per page: 20 Total: 4310 page: [<<][<][01][02][03][04][05][06][07][08][09][10][>][>>]
function Page_bar ($coloro = "#000000", $colorn = "Red") {
Return "









". $this->total_bar ()." ". $this->mun_bar ()." ". $this->jump_bar ()."
". $this->mm_jumpmenu ();
}

function Taketime ($color = "#000000")//Calculate Execution time
{
Return "page Execution Time". ABS ((Microtime ()-$this->starttime) * 1000). " Milliseconds ";
}

function style ()//output pagination style
{
$style _num = $this->style;

if ($this->totalpage! = 0)//If the total number of pages = 0, indicates no paging
{
Switch ($style _num) {
Case 1:
return $this->page_bar ();
Page: 1/4310 per page: 20 Total: 4310 page: [<<][<][01][02][03][04][05][06][07][08][09][10][>][>>]
Break
Case 2:
echo $this->mun_bar ();
The entire digital navigation bar [<<][<][01][02][03][04][05][06][07][08][09][10][>][>>]
Break
Case 3:
echo $this->page_button ();
The entire digital navigation bar [<][01][02][03][04][05][06][07][08][09][10][>]
Break
}
}
}

function Mm_jumpmenu ()//Jump for Web effects
{
window.open (SELOBJ.OPTIONS[SELOBJ.SELECTEDINDEX].VALUE,TARG);
Return "";
}

function First_groud ($char = "<<", $color = "#000000") {
if ($this->page = = 1) {
Return "". $char. "";
} else {
$pre _gpage= ($this->page-$this->bar_mid<0) 1: $this->page-$this->bar_mid;
$pre _gpage = 1;
Return "key." Page= ". $pre _gpage. $this->link." Title= "on a group of" > ". $char." ";
}
}

function Last_groud ($char = ">>", $color = "#000000") {
if ($this->page = = $this->totalpage) {
Return "". $char. "";
} else {
$pre _gpage= ($this->page-$this->bar_mid<0) 1: $this->page-$this->bar_mid;
$pre _gpage = $this->totalpage;
Return "key." Page= ". $pre _gpage. $this->link." Title= "on a group of" > ". $char." ";
}
}
}

http://www.bkjia.com/PHPjc/631723.html www.bkjia.com true http://www.bkjia.com/PHPjc/631723.html techarticle This is a relatively perfect paging class, support form input jump, also support select Jump paging, but also support on 10 pages, the next 10 page offset paging OH. * * This is a relatively perfect ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.