Throw out a function compared to the higher paging class (for php5.x) _php tutorial

Source: Internet
Author: User
Throw out a function compared to the higher paging class (for php5.x)
Workaround
Fear level is not high, so never let go of any code, this class I have used for a long time, recently with object-oriented method rewrite, apply to php5.x, specially throw out, not afraid of laughed at, hope.
This class is used for paging, and component pages with database queries. The following methods are used.

/*

* Name: Pagination class

* Description: For pagination of several component pages and with SQL queries

* Author: idlion | | Moonfly ([Email=id_lion@hotmail.com]id_lion@hotmail.com[/email])

* Creation Time: 20060218

* Last modified: 20070524

*/

Class PageBreak {

Private $mTotalRowsNum = 0; Total lines of information

Private $mCurPageNumber = 1; Your current page

Private $mTotalPagesNum = 1; Total pages

Private $mQueryString; The data passed by the page (the string after the URL?)

Private $mPageRowsNum = 20; Number of rows displayed per page

Private $mIndexBarLength = 5; Number of pages in index bar

Private $mIndexBar = '; Page Index Bar

Private $mPageInfo = '; Paging information

Page number index bar style

Private $mNextButton = "8";

Private $mPreButton = "7";

Private $mFirstButton = "9";

Private $mLastButton = ":";

Private $mCssIndexBarCurPage = "Fontweight:bold;color: #FF0000";

Private $mCssIndexBarPage = ';

Pagination Information Style

Private $mCssPageInfoNumFont = ' color: #FF0000 ';

Private $mCssPageInfoFont = ';



Construction method

Public function __construct (& $rSqlQuery, $userPageRowsNum = ') {

if (!is_array ($rSqlQuery)) {

$this >setdbpagebreak ($rSqlQuery, $userPageRowsNum);

}

else {

$this >setarraypagebreak ($rSqlQuery, $userPageRowsNum);

}

}



Set Database type Paging

Private Function Setdbpagebreak (& $rSqlQuery, $userPageRowsNum = ') {

$this >setdbtotalrowsnum ($rSqlQuery);

$this >settotalpagesnum ($userPageRowsNum);

if ($this >mtotalpagesnum > 1) {

$this >setcurpagenumber ();

$this >setsqlquery ($rSqlQuery);

$this >setquerystring ();

$this >setindexbar ();

$this >setpageinfo ();

}

}



Set up array-type paging

Private Function Setarraypagebreak (& $rArray, $userPageRowsNum = ', $userTotalRowsNum = ') {

$this >setarraytotalrowsnum ($rArray, $userTotalRowsNum);

$this >settotalpagesnum ($userPageRowsNum);

if ($this >mtotalpagesnum > 1) {

$this >setcurpagenumber ();

$this >setarray ($rArray);

$this >setquerystring ();

$this >setindexbar ();

$this >setpageinfo ();

}

}



Database type calculation total number of rows

Private Function Setdbtotalrowsnum ($rSqlQuery) {

$this >mtotalrowsnum = mysql_num_rows (mysql_query ($rSqlQuery));

}



Array type calculation total number of rows

Private Function Setarraytotalrowsnum ($array) {

$this >mtotalrowsnum = count ($array);

}



Calculate Total Pages

Private Function settotalpagesnum ($userPageRowsNum = ") {

if ($userPageRowsNum) {

$this >mpagerowsnum = $userPageRowsNum;

}

$this >mtotalpagesnum = (int) (Floor (($this >mtotalrowsnum1)/$this >mpagerowsnum) +1);

}



Calculate Current Page Count

Private Function Setcurpagenumber () {

if ($_get[' cur_page ']) {

$this >mcurpagenumber = $_get[' cur_page ');

}

}



Fix SQL Intercept statement

Private Function Setsqlquery (& $rSqlQuery) {

$start _number = ($this >mcurpagenumber1) * $this >mPageRowsNum;

$rSqlQuery. = "LIMIT". $start _number. ",". $this >mPageRowsNum;

}



Fixed an array after interception

Private Function SetArray (& $rArray) {

$start _number = ($this >mcurpagenumber1) * $this >mPageRowsNum;

$rArray = Array_slice ($rArray, $start _number, $this >mpagerowsnum);

}



Fix $_get Pass Data

Private Function setquerystring () {

$query _string = $_server[' query_string ');

if ($query _string = = ") {

$this >mquerystring = "cur_page=";

}

else {

$this >mquerystring = preg_replace ("/&?cur_page=d+/", "", $query _string);

$this >mquerystring = "?". $this >mquerystring. " &cur_page= ";

}

}



Set page number Index bar

Private Function Getpageindex () {

if ($this >mtotalpagesnum <= $this >mindexbarlength) {

$first _number = 1;

$last _number = $this >mTotalPagesNum;

}

else {

$offset = (int) floor ($this &GT;MINDEXBARLENGTH/2);

if (($this >mcurpagenumber$offset) <= 1) {

$first _number = 1;

}

ElseIf (($this >mcurpagenumber+ $offset) > $this >mtotalpagesnum) {

$first _number = $this >mTotalPagesNum$this>mIndexBarLength+1;

}

else {

$first _number = $this >mCurPageNumber$offset;

}

$last _number = $first _number+ $this >mIndexBarLength1;

}

$last _number;

for ($i = $first _number; $i <= $last _number; $i + +) {

if ($this >mcurpagenumber = = $i) {

$page _index. = "Mcssindexbarcurpage." > ". $i." ";

}

else {

$page _index. = "mquerystring. $i." ' style= '. $this >mcssindexbarpage. " > ". $i." ";

}

}

return $page _index;

}



Set page number Index bar

Private Function Setindexbar () {

$this >mindexbar = $this >getnavfirstbutton ();

$this >mindexbar. = $this >getnavprebutton ();

$this >mindexbar. = $this >getpageindex ();

$this >mindexbar. = $this >getnavnextbutton ();

$this >mindexbar. = $this >getnavlastbutton ();

}



Get page number Index bar Home button

Private Function Getnavfirstbutton () {

Return "mquerystring." 1 ' > ". $this >mfirstbutton." ";

}



Get page number index bar previous page button

Private Function Getnavprebutton () {

if ($this >mcurpagenumber>1) {

$pre _number = $this >mCurPageNumber1;

}

else {

$pre _number = 1;

}

Return "mquerystring. $pre _number." > ". $this >mprebutton." ";

}



Get page number index bar next page button

Private Function Getnavnextbutton () {

if ($this >mCurPageNumber< $this >mtotalpagesnum) {

$next _number = $this >mCurPageNumber+1;

}

else {

$next _number = $this >mTotalPagesNum;

}

Return "mquerystring. $next _number." > ". $this >mnextbutton." ";

}



Get page number index bar last button

Private Function Getnavlastbutton () {

Return "mquerystring. $this >mtotalpagesnum." > ". $this >mlastbutton." ";

}



Set Paging information

Private Function Setpageinfo () {

$this >mpageinfo = "Mcsspageinfofont." > ";

$this >mpageinfo. = "Total Mcsspageinfonumfont." > ". $this >mtotalrowsnum." message | ";

$this >mpageinfo. = "Mcsspageinfonumfont." > ". $this >mpagerowsnum." Bar/page | ";

$this >mpageinfo. = "Total Mcsspageinfonumfont." > ". $this >mtotalpagesnum." Page | ";

$this >mpageinfo. = "Mcsspageinfonumfont." > ". $this >mcurpagenumber. Page";

$this >mpageinfo. = "";

}



Remove Page number Index bar

Public Function Getindexbar () {

return $this >mIndexBar;

}



Remove paging information

Public Function GetPageInfo () {

return $this >mPageInfo;

}



}

?>


Copy Code Usage 1: Working with the database (in the case of my own database operations class and template Class)//This is a SQL query statement, we will make a page of its query results

$sql = "SELECT * from member";



Reading a paging class

Require_once ("pagebreak.php");



Paging initialization

$SQL is the query statement above

20 is the number displayed per page

With the initialization of the paging class, the query is added "limit ... "

$pagebreak = new PageBreak ($sql, 20);



Raw Ingredients page Index navigation bar

$navbar = $pagebreak >getpageinfo (). $pagebreak >getindexbar ();



Query results (here with my own class, not much to say)

$result = $db >getfieldsarray ($sql)



Output query Results

Var_dump ($result);



Output Paging index navigation bar

Echo $navbar;


Copy Code Usage 2: match the array to output//This is a SQL query statement and get the query results

$sql = "SELECT * from member";

$result = $db >getfieldsarray ($sql);



Reading a paging class

Require_once ("pagebreak.php");



Paging initialization

$result is the result of the query above

20 is the number displayed per page

By the initialization of the pagination class, the result array is automatically truncated to the information content of the corresponding page.

$pagebreak = new PageBreak ($result, 20);



Raw Ingredients page Index navigation bar

$navbar = $pagebreak >getpageinfo (). $pagebreak >getindexbar ();



Output query Results

Var_dump ($result);



Output Paging index navigation bar

Echo $navbar;


The copy code below is the output style,
The first half of the Information Bar, is $pagebreak>getpageinfo ()
The second half of the page index navigation, is $pagebreak>getindexbar ()



Output content and style can be easily adjusted in the class, very simple, interested can study

[ ]
Attachments: The user group you are in cannot download or view attachments

d8888d Huitie Content
Good things, how not to play a bag, easy to learn AH: $
d8888d Huitie Content
This is a sort of news list page. Not the content of the news page ..... This is the [url=http://www.phpchina.cn/bbs/viewthread.php?tid=12999] link marker http://www.phpchina.cn/bbs/viewthread.php?tid= 12999[/url] is the pagination of the content:

[ ]
d8888d Huitie Content
[Img]http://www.phpchina.com/bbs/images/smilies/default/victory.gif[/img] [img]http://www.phpchina.com/bbs/ images/smilies/default/victory.gif[/img][img]http://www.phpchina.com/bbs/images/smilies/default/victory.gif[/ img
d8888d Huitie Content
Very good
Have code
with annotations
There are application examples

Very much expect everyone to use this form to send code
d8888d Huitie Content
:) :) :) :)
d8888d Huitie Content
There's a problem, that's it. Ordy by ... Where is it written?
I don't know how to ask 1.
d8888d Huitie Content
Why can't output paging navigation ..... Can not be described in detail under! I am a novice!
d8888d Huitie Content
How to do so much: (
d8888d Huitie Content
Originally Posted by Orclord on 200761 09:43 [url=http://www.phpchina.com/bbs/redirect.php?goto=findpost&pid=201879&ptid= 26485] link marker [Img]http://www.phpchina.com/bbs/images/common/back.gif[/img][/url]
There's a problem, that's it. Ordy by ... Where is it written?
I don't know how to ask 1.
In addition to limit .... Information, others are in the $sql.
The Setsqlquery method can automatically add limit to the $sql statement .... Content.

http://www.bkjia.com/PHPjc/632528.html www.bkjia.com true http://www.bkjia.com/PHPjc/632528.html techarticle throw a function compared to the higher page class (for php5.x) resolution method Afraid of the level is not high, so never let go of any code, this class I have used for a long time, recently with object-oriented ...

  • 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.