Which one to help to see this page class how to call, I say is under the query statement

Source: Internet
Author: User
Tags benchmark
Find a better page on the web, although the author has explained how to call, but for me still do not understand, mainly in the SQL statement inside how to call, the following is the page class code:
 ' 100 ', the total number of bars required to display the data; * (required) ' pageSize ' + ' 2 ', the number of codes required per page, * (required) ' currentpage ' =>$_get[' P ', the current page number, by default can be $_get[' P ') Get, where the name P can be customized * (required) ' baseUrl ' = '/welcome?id=3 ', the link address of your current page, such as http://www.xxx.com/test.php (or/test.php), If the following parameters can be http://www.xxx.com/test?id=8 * (optional, the default is 3) ' offset ' = ' 3 ', the current page number of the left and right offset, such as the current page number is 5, then around 5 shows a few digital links, the default is 3, The effect is 2,3,4,5,6,7,8 * (optional, the default is P) ' pagestring ' = ' P ', by $_get[' P '] to get the current page name, the default is P * (optional, the default is here) ' className ' = ' Here ', the style of the current page link button, the default style is named here, so you can write CSS styles like this. here{background: #FF4500;}) * * 2, the method can be used. * A, after initializing the class, you need to call pagination ([$style = ' 1 '] [, $output =true]) method to generate a paging link * Description of the parameter: * @param $style (default is 1, not fill in): Get link all components, that is, home + Previous + Digital link + next + last * @param $style = = 2: Get digital link only * @param $style = = 3: Get previous page + next page * @param $style = = 4: Get previous page + Number link + next page, (no Include pages) * * @param $output (default is True), return page link * @param $output false, Direct output Paging link * * B, getcurrentpage () Get the current page number, after the authenticity of the judgment, Prevent users from entering errors themselves, such as http://www.xxx.com/test?p=-100; This method gets the current page number 1 * * C, Pageamount () Get the total page count * * @auThor * @link HTTP://BLOG.SINA.COM.CN/YANYINGHQ * */class page{private $pageSize;//The number of list bars displayed on each page of your site private $tot Alrows; Total number of record entries returned through database queries private $url; Base URL private $pageAmount; The total number of pages is private $currentPage; The current page number is private $offset = 4; Page offset Private $pageString = ' P '; The name of the page number in the URL is private $classHere = ' class= ' here '; The class name of the current page link, the default is here//Initialize the current page number, record the total number of bars, how many records per page public function __construct ($param) {$this->pag        esize = $param [' pageSize '];        $this->totalrows = $param [' totalrows '];        $this->url = $param [' BaseUrl '];        $this->offset =!empty ($param [' offset '])? $param [' Offset ']: $this->offset;        $this->pagestring =!empty ($param [' pagestring '])? $param [' pagestring ']: $this->pagestring;        $this->classhere =!empty ($param [' className '])? $param [' ClassName ']: $this->classhere;    $this->currentpage = (int) $param [' currentpage ']; }/** * Create page links * * @param $styleThink 1: Get links all components * @param $style = = 2: Get digital links only * @param $style = = 3: Get previous page, next page * @param $style = = 4: Get previous page, next page only , digital links, not including pages * * @param $output to True, return page link * @param $output false, Direct output Paging link * */public funct        Ion pagination ($style = ' 1 ', $output =true) {$this->baseurl ();        $this->pageamount ();                     $this->currentpage (); Get all Components if ($style = = ' 1 ') {$page = $this->indexpage (). $this->prevpage (). $this->pagenum        ber (). $this->nextpage (). $this->endpage ();        } else if ($style = = ' 2 ') {//Get a pure digital link $page = $this->pagenumber (); } else if ($style = = ' 3 ') {//Get previous page Next $page = $this->prevpage (). $this->nextpage        (); } else if ($style = = ' 4 ') {//previous page, next page, digital link $page = $this->prevpage (). $this->pagenu        Mber (). $this->nextpage ();                 }if ($output) {return $page;        } else {echo $page; }}/** * Gets the current page number * * @return The current page number, through the authenticity of the */Public Function Getcurrentpage () {$        This->pageamount ();        $this->currentpage ();    return $this->currentpage; }/** * Calculates all the pages * * can call this method directly outside the class to return the total number of pages * * @return Number of pages * * Public Function Pageamou        NT () {$this->pageamount = ceil ($this->totalrows/$this->pagesize);        if ($this->pageamount <= 0) {$this->pageamount = ' 1 ';    } return $this->pageamount; /** * Determine if the benchmark link carries parameters * * Benchmark link for user to submit the current page Number link * * If carrying parameters, then add &p= after link * * If no parameters are taken, directly add p= */Private Function BaseUrl () {if (Preg_match ('/\?/', $this->url)) {$this->u RL = $this->url. ' & '. $this->pagestring. '        =';    } else {        $this->url = $this->url. '? '. $this->pagestring. '        =';      }}/** * Verify the authenticity of the current page number * * If the current page number is less than 1 or not, the default current page number is 1 * * If the current page number is greater than the total page count, the default current page number is total page numbers *            */Private Function currentpage () {if ($this->currentpage < 1 | |! $this->currentpage) {        $this->currentpage = 1; } else if (($this->currentpage > $this->pageamount) {$this->currentpage = $this        Pageamount;        }}/** * Homepage link */Private function indexpage () {if ($this->currentpage = = 1) return;    Return ' URL. ' 1 ' > Home '; }/** * Last link */Private function EndPage () {if ($this->currentpage = = $this->pageamount        ) return; Return ' URL. $this->pageamount. ' "    > Last ';        }/** * Previous page */Private Function prevpage () {if ($this->currentpage = = 1) return; Return ' URL. ($this->currentpage-1 ).'"    > previous page '; }/** * Next page */Private Function nextPage () {if ($this->currentpage = = $this->pageamount        ) return; Return ' URL. ($this->currentpage + 1). ' "    > next page ';        /** * * */Private Function pagenumber () {$left = "";                 $right = "";            If the total number of records is "greater than" the number of all links if ($this->pageamount > ($this->offset * 2 + 1)) {//the current page distance from the first page                         $leftNum = $this->currentpage-1;                         Distance of current page distance from last $rightNum = $this->pageamount-$this->currentpage;                When the current page number is less than the offset of the first page, the missing small squares on the right ($leftNum < $this->offset) {//Left link for ($i = $leftNum; $i >= 1; $i-) {$left. = ' URL. ($this->current page-$i). ' " > '.                ($this->currentpage-$i). "; }                                 //The link on the right for ($j = 1; $j <= ($this->offset * 2-$leftNum); $j + +) {$ri ght. = ' URL. ($this->currentpage + $j). ' " > '.                ($this->currentpage + $j). "; }} else if ($rightNum < $this->offset) {//Left link for ( $i = ($this->offset * 2-$rightNum); $i >= 1; $i-) {$left. = ' URL. ($this->currentpage-$i). ' " > '.                ($this->currentpage-$i). ";                    }//The link on the right for ($j = 1; $j <= $rightNum; $j + +) { $right. = ' URL. ($this->currentpage + $j). ' " > '.                ($this->currentpage + $j). "; }} else {//the link to the left of the current link for ($i = $this->offset; $i >= 1; $i-) {$left. = ' URL. ($this->currentpage-$i). ' " > '.($this->currentpage-$i). ";                     }//The link to the right of the current link for ($j = 1; $j <= $this->offset; $j +) { $right. = ' URL. ($this->currentpage + $j). ' " > '.                ($this->currentpage + $j). "; }} return $left. ' URL. $this->currentpage. ' class= ' here ' > '. $this->currentpage.        $right;            } else {$allLink = '; When the total number of pages is less than the number of links that need to be displayed, all displays for ($j = 1; $j <= $this->pageamount; $j + +) {$all link.= ' URL. $j. ' ". ($j = = $this->currentpage? $this->classhere: '). '            > '. $j. ';        } return $allLink; }    } }


Reply to discussion (solution)

Here is the PHP call page, the following code:

 
  
 <title>Untitled Document</title>  
 ' + ', ' pageSize ' = ' 2 ', ' currentpage ' =>@$_get[' P '], ' baseUrl ' = '/page_index.php?id=3 '); $page 1 = new page ($param), $page 2 = new page ($param), $page 3 = new page ($param), $page 4 = new page ($param), $page 5 = new page ( $param); This should be the SQL query statement, but how to call the paging function I do not know how to write the Echo ' total record: ', Echo '
 
  
 '; Echo ' 2 records per page
 
  
 '; Echo ' current page: '. $page 1->getcurrentpage (). '
 
  
 '; Echo ' total '. $page 1->pageamount (). ' Page
 
  
 '; Echo '
  • '. $page 1->pagination (). '
  • '; Echo '
  • '. $page 2->pagination (' 1 '). '
  • '; The default is 1, so echo ' does not fill the effect like '
  • '. $page 3->pagination (' 2 '). '
  • '; Echo '
  • '. $page 4->pagination (' 3 '). '
  • '; Echo '
  • '. $page 5->pagination (' 4 '). '
  • ';? >

    This class is only responsible for the generation of page strips.
    The only thing that might be related to a database query is the parameter array $param [' totalrows '] Item
    Because the total number of rows to be paged is the query, the query should be completed before the $param assignment

    This class is only responsible for the generation of page strips.
    The only thing that might be related to a database query is the parameter array $param [' totalrows '] Item
    Because the total number of rows to be paged is the query, the query should be completed before the $param assignment


    What should the moderator say?

    Landlord is lazy enough, I have a here for you, the style is written

     "Records", "Prev" and "prev", "Next" = "Next", "first" = "Home", "last" and "End"); Private $listNum =8;/* $total 11. * $listRows 12. */Public function __construct ($total, $listRows =10, $pa = "") {$this->total= $total; $this->listrows= $listRows; $t his->uri= $this->geturi ($PA); $this->page=!empty ($_get["page"])?   $_get["Page"]: 1; $this->pagenum=ceil ($this->total/$this->listrows); $this->limit= $this->setlimit (); } Private Function Setlimit () {return ' Limit '.  $this->page-1) * $this->listrows. ", {$this->listrows}"; } Private Function GetURI ($PA) {$url =$_server["Request_uri"]. ( Strpos ($_server["Request_uri"], '? ')? ': '? ').   $PA;  $parse =parse_url ($url);   if (Isset ($parse ["Query"])) {parse_str ($parse [' query '], $params); unset ($params ["page"]); $url = $parse [' Path '].    Http_build_query ($params);  } return $url;  The Public Function __get ($args) {if ($args = = "Limit") return $this->limit;  else return null;  } Private Function Start () {if ($this->total==0) return 0;  else return ($this->page-1) * $this->listrows+1; Private Function End () {return min ($this->page* $this->listrows, $this->total);} Private Function First () {if (  $this->page==1) $html. = '; else $html. = "
  • Uri}&page=1 ' >{$this->config["First"]}
  • "; return $html; The Private Function prev () {if ($this->page==1) $html. = "; else $html. ="
  • Uri}&page= ". ($this->page-1). "' >{$this->config["Prev"}
  • "; return $html; } Private Function PageList () {$linkPage = ""; $inum =floor ($this-&GT;LISTNUM/2); for ($i = $inum; $i >=1; $i-) {$page = $this->page-$i; if ($page <1) continue; $linkPage. = "
  • uri}&page={$page} ' >{$page}
  • "; } $linkPage. = "
  • {$this->page}
  • "; for ($i = 1; $i <= $inum; $i + +) {$page = $this->page+ $i, if ($page <= $this->pagenum) $linkPage. = "
  • uri}&page={$page} ' >{$page}
  • "; Else break;} return $linkPage;} Private function Next () {if ($this->page== $this->pagenum) $html. = '; else $html. = "
  • Uri}&page= ". ($this->page+1). "' >{$this->config["Next"}
  • "; return $html;} Private Function Last () {if ($this->page== $this->pagenum) $html. = "; else$html.="
  • Uri}&page= ". ($this->pagenum). "' >{$this->config["Last"]}
  • "; return $html;} /*private function Gopage () {return ' ';} */private function Gopage () {return '';} function Fpage ($display =array (0,1,2,3,4,5,6,7,8)) {$html [0]=] Total{$this->total}{$this->config["header"]} "; $html [1]=] Display per page". ($this->end ()-$this->start () +1). "Bar, this page{$this->start ()}-{$this->end ()}Article "; $html [2]=]{$this->page}/{$this->pagenum}Page "; $html [3]= $this->first (); $html [4]= $this->prev (); $html [5]= $this->pagelist (); $html [6]= $this->next ( ); $html [7]= $this->last (); $html [8]= $this->gopage (); $fpage = '; foreach ($display as $index) {$fpage. = $html [$ index];} return $fpage;} }?>

    Specific invocation method:
    $num = 15; Number of displays per page
    $page =new page ($total, $num);
    $result = $db->query ("SELECT * from". $db->table (' article '). $where. "ORDER BY addtime desc {$page->limit}");
    Cycle
    Fpage (Array (3,4,5,6,7,0,1,2,8));? >//php Paging Class call, these numbers can go to the class file inside see
      fpage (Array (3,4,5,6,7,8));? >
    This is what I call the
    CSS style files
    . fenye li{float:left; font-family:arial, Helvetica, Sans-serif; margin-left:6px; display:inline; line-height:30px;}
    . fenye a{display:block;height:30px; min-width:30px; text-align:center; font-size:14px; border:1px solid #d6d6d6; float : Left; margin-left:3px; padding:3px 5px;line-height:30px;text-decoration:none;color: #666;}
    . Fenye a:hover{background: #FF4500; border-color: #FF4500; color: #FFF;}
    . Fenye a.here{background: #FF4500; border-color: #FF4500; color: #FFF;}
    . Fenye. Sel{background: #E5EDF2; color: #333; font-weight:bold; border:1px #C2D5E3 solid; padding:0 12px; BORDER-RADIUS:4PX}
    On the following:

    Any friend who needs it can take it with you.

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