Ajax No Refresh Paging class

Source: Internet
Author: User

<?php class Page { //  page columns per page public  $rollPage  = 10;//  Number of pages to be taken with the parameter public  $parameter;//  default list of rows per page public  $listRows  = 20;//  starting line number public   $firstRow;//  Total number of pages protected  $totalPages;//  rows protected  $totalRows;//  The current page protected  $nowPage;//  The total number of pages in the column protected  $coolPages;//  pagination display custom protected  $config  = array (' header '  =>  ' record ',  ' prev '  =>  ' prev ',  ' Next '  =>   ' Next ',  ' first '  =>  ' home ',  ' last '  =>  ' End ',  ' theme '  =>   '  %totalRow% %header% %nowPage%/%totalPage%  page  %upPage%  %first%   %prepage%  %linkpage% %downpage% %nextpage% %end% %ajax% ');//  The default paging variable name protected  $varPage;//idprotected  $pagesId of the outer div of the page;//The paging content replaces the target idprotected  $target;  /* *+----------------------------------------------------------*  schema functions +----------------------------------------------------------*  @access   public+----------------------------------------------------------*  @param  array  $totalRows    Total Records *  @param  array  $listRows    number of records per page *  @param  array $ parameter   parameters of Paging jump +----------------------------------------------------------*/public function  __construct ($totalRows,  $listRows  =  ',  $parameter  =  ', $target = ', $ Pagesid= ")  {$this->totalrows =  $totalRows $this->parameter =  $parameter; $this- >target =  $target $this->pagesid =  $pagesId $this->varpage = c (' Var_ PAGE ')  ? c (' var_page ')  :  ' P ';if  (!empty ($listRows))  {$this->listrows =  intval ($listRows);} $this->totalpages = ceil ($this->totalrows /  $this->listrows);      //Total pages $this->coolpages = ceil ($this->totalpages /  $this->rollpage); $this Nowpage = !empty ($_get[$this->varpage])  ? intval ($_get[$this->varpage])  :  1;if  (!empty ($this->totalpages)  &&  $this->nowpage >  $this TotalPages)  {$this->nowpage =  $this->totalpages;} $this->firstrow =  $this->listrows *  ($this->nowpage - 1);}  public function setconfig ($name,  $value)  {if  (isset ($this->config[$name))  {$this->config[$name] =  $value;}  /**+----------------------------------------------------------*  Paging display output +---------------------------- ------------------------------*  @access  public+----------------------------------------------------- -----*/public function show ()  {if  (0 ==  $this->totalrows) return  "; $p  =  $this->varpaGE, $nowCoolPage  = ceil ($this->nowpage /  $this->rollpage); $url  = $_server[' Request_uri '] .  (Strpos ($_server[' Request_uri '],  '? ')  ?  '  :  '? ')  .  $this->parameter; $parse  = parse_url ($url);if  (Isset ($parse [' query '])  { Parse_str ($parse [' query '],  $params); unset ($params [$p]); $url  =  $parse [' Path '] .  '? '  . http_build_query ($params);} Page up and down string $uprow =  $this->nowpage - 1; $downRow  =  $this->nowpage +  1;if  ($upRow  > 0)  {$upPage  =  "<a href="  .  $url   .  "&"  .  $p  .  "= $upRow ' >"  .  $this->config[' prev '] .  " </a> ";}  else {$upPage  =  "";}  if  ($downRow  <=  $this->totalpages)  {$downPage  =  "<a href="  .  $url  .  &  . $p .  "= $downRow ' >"  .  $this->config[' Next '] .  "</a>";}  else {$downPage  =  "";}  << < > >>if  ($nowCoolPage  == 1)  {$theFirst  =   ""; $prePage  =  "";}  else {$preRow  =  $this->nowpage -  $this->rollpage; $prePage  =  " <a href= '  .  $url  .  &  .  $p  .  "= $preRow '  >"  .  $this->rollpage .  "page </a>", $theFirst  =  "<a href=" "&NBSP;.   $url  .  &  .  $p  .  "=1 '  >"  .  $this->config[' first ' ] .  "</a>";} if  ($nowCoolPage  ==  $this->coolpages)  {$nextPage  =  ""; $theEnd  =  "";}  else {$nextRow  =  $this->nowpage +  $this->rollpage; $theEndRow  =  $this->totalpages; $nextPage  =&nbsP; " <a href= '  .  $url  .  &  .  $p  .  "= $nextRow '  >"  .  $this->rollpage .  "page </a>" $theEnd  =  "<a href="  .  $url  .  &  .  $p  .  "= $theEndRow '  >"  .  $this->config[' Last '] .  ' </a> ';}  1 2 3 4 5$linkPage =  "";for  ($i  = 1;  $i  <=   $this->rollpage;  $i + +)  {$page  =  ($nowCoolPage  - 1)  *  $this- >rollPage +  $i;if  ($page  !=  $this->nowpage)  {if  ($page  <=   $this->totalpages)  {$linkPage  .=  "&nbsp;<a href="  .  $url  .   &  .  $p  .  "= $page ' >&nbsp;"  .  $page  .  &nbsp;</a>;}  else {break;}}  else {if  ($this->totalpages != 1) &nbSp {$linkPage  .=  &nbsp;<span class= ' current ' > '  .  $page  .  ' </span > ";}}} <script>jquery paging </script> $ajax  =  "; if ($this->target) {$ajax  = << <eco<script>jquery (function ($)  {$ (' #{$this->pagesid} a '). Click (function () {$.ajax ({URL:  $ (This). attr (' href '),datatype:  "html",type:  "POST", Cache: false,success: function ( HTML) {$ ("#{$this->target}"). html (HTML);}}); (Return false;});}); </script>eco;} $pageStr  = str_replace (Array ('%header% ', '%nowpage% ', '%totalrow% ', '%totalpage% ', '%uppage% ', '%downpage ' % ', '%first% ', '%prepage% ', '%linkpage% ', '%nextpage% ', '%end% ', '%ajax% '), Array ($this->config[' header '], $this- >nowpage, $this->totalrows, $this->totalpages, $upPage,  $downPage, $theFirst,  $prePage, $ linkpage,  $nextPage, $theEnd, $ajax), $this->config[' theme ');return  $pageStr;}}

Calling method: in TP:

Public function ajaxpage () {                  $tz =m (' Moneylog ');         import (' ORG. Util.ajaxpage ');         $count  =  $tz->count ();           $page  = new page ($count, ten, ' type=1 ', ' Ajax_div ', ' Ajax_page_div ');                     $data  =  $tz->limit ($page->firstrow,  $page->listrows) Select ();         $pagestr  =   $page->show ();          $this->assign (' list ', $data);          $this->assign (' show ', $pagestr);         if (Is_ajax) {       &nbsP;    exit ($this->fetch (' list '));         }          $this->display (' list ');             }

Static page:

<script type= "Text/javascript" src= "/public/shouye/js/jquery-1.7.1.min.js" ></script><div id= "Ajax_ Div "><table>    <tr>        <td> sex </td><td> age </td><td> units </td>    </tr>    <?php foreach ($list as $v) {?>        <tr>        <td><?php echo $v [' Total_money ?></td>        <td><?php echo $v [' time '];?></td>         <td><?php echo $v [' IP '];? ></td>         </tr>         <?php}?>        </table>    <div><div id= "Ajax_page_ Div ">{$show}</div></div></div><script>jquery (function ($) {$ (' #ajax_page_div a '). Click (function () {$.ajax ({URL: $ (this). attr (' href '), DataType: "HTML", type: "POST", Data: ' zhangsan= ' + ' Lisi ', Cache:false, Success:function (HTML) {$ ("#ajax_div"). HTML (HTML);}}); return false;}); </script>





Ajax No Refresh Paging class

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.