Thinkphp 3.2 Ajax No refresh paging (not completely changed, temporary use)

Source: Internet
Author: User
Tags learn php

The page class after a temporary change (many places have not been modified ...) Because I did not learn PHP. Following

<?php
namespace Fenye\libs;
/**
file:page.class.php
Perfect Paging Class page
*/
Class Page {
Private $total; Total number of records in the data table
Private $listRows; Number of rows displayed per page
Private $limit; The SQL statement uses the LIMIT clause to restrict the number of records fetched
Private $uri; Get URL Request address automatically
Private $pageNum; Total pages
Private $page; Current page
Private $config = Array (
' Head ' = ' record ',
' Prev ' = ' prev ',
' Next ' = ' next page ',
' First ' = ' home ',
' Last ' = ' End '
);
Display content in the paging information, you can set it yourself through the set () method
Private $listNum = 10; The number of default page list displays

/**
Construction method, you can set the properties of the paging class
@param int $total Calculate the total number of records for paging
@param int $listRows Optional, set the number of records to display per page, default to 25
@param mixed $query optional, to pass parameters to the target page, either an array or a query string format
@param bool $ord Optional, the default value is True, the page appears from the first page, False is the last page
*/

Public function __construct ($total, $listRows =25, $wurl = "", $query = "", $ord =true) {
$this->total = $total;
$this->listrows = $listRows;
$this->uri = $this->geturi ($query);
$this->pagenum = ceil ($this->total/$this->listrows);
/* The following judgment is used to set the current face */
if (!empty ($wurl)) {
$page = $wurl;
}else{
if ($ord)
$page = 1;
Else
$page = $this->pagenum;
}

if ($total > 0) {
if (Preg_match ('/\d/', $page)) {
$this->page = 1;
}else{
$this->page = $page;
}
}else{
$this->page = 0;
}

$this->limit = $this->setlimit ();
}

/**
Used to set the display of paging information, can be consistent operation
@param string $param is the subscript of the member Property array config
@param string $value to set the element value corresponding to the config subscript
@return object returns the object itself $this, for use in a habitual operation
*/
function set ($param, $value) {
if (Array_key_exists ($param, $this->config)) {
$this->config[$param] = $value;
}
return $this;
}

/* is not a direct call, this method allows you to get the value of the private member property limit and page directly outside the object */
function __get ($args) {
if ($args = = "Limit" | | $args = = "Page")
return $this $args;
Else
return null;
}

/**
Output paging in the specified format
The numbers @param int 0-7, respectively, are used as parameters to customize the output paging structure and the order of the structure, with the default output of all structures
@return String Paging information content
*/
function Fpage () {
$arr = Func_get_args ();

$html [0] = "<span class= ' p1 ' >&nbsp; total <b> {$this->total} </b>{$this->config[" Head "]}& Nbsp;</span> ";
$html [1] = "&nbsp; page <b>". $this->disnum (). " </b> Bar &nbsp; ";
$html [2] = "&nbsp; this page from <b>{$this->start ()}-{$this->end ()}</b> strip &nbsp;";
$html [3] = "&nbsp;<b>{$this->page}/<span id= ' zyl ' >{$this->pagenum}<span></b> page &nbsp; ";
$html [4] = $this->firstprev ();
$html [5] = $this->pagelist ();
$html [6] = $this->nextlast ();
$html [7] = $this->gopage ();

$fpage = ' <div style= ' font:12px \ ' \5b8b\4f53\ ', San-serif; " > ';
if (count ($arr) < 1)
$arr = Array (0, 1,2,3,4,5,6,7);

for ($i = 0; $i < count ($arr); $i + +)
$fpage. = $html [$arr [$i]];

$fpage. = ' </div> ';
return $fpage;
}

/* Private method used inside the object, */
Private Function Setlimit () {
if ($this->page > 0)
Return ($this->page-1) * $this->listrows. ", {$this->listrows}";
Else
return 0;
}

  /* The private method used inside the object to automatically get the current URL of the access */
  private function GetURI ($query) { 
     $request _uri = $wurl;  //change here
    $url = strstr ($request _uri, '? ')? $request _uri: & nbsp $request _uri. '? ';
   
   if (Is_array ($query))
     $url. = Http_build_ Query ($query);
   else if ($query! = ")
     $url. =" & ". Trim ($query,"?& ");
  
    $arr = Parse_url ($url);

if (Isset ($arr ["Query"])) {
Parse_str ($arr ["Query"], $arrs);
unset ($arrs ["page"]);
$url = $arr ["path"]. '? '. Http_build_query ($ARRS);
}

if (Strstr ($url, '? ')) {
if (substr ($url,-1)! = '? ')
$url = $url. ' & ';
}else{
$url = $url. '? ';
}

return $url;
}

/* Private method used inside the object to get the number of records starting at the current page */
Private Function Start () {
if ($this->total = = 0)
return 0;
Else
Return ($this->page-1) * $this->listrows+1;
}

/* Private method used inside the object to get the number of records at the end of the current page */
Private Function End () {
return min ($this->page * $this->listrows, $this->total);
}

/* Private method used inside the object to get operation information for the previous and first page */
Private Function Firstprev () {
if ($this->page > 1) {
$str = "&nbsp;<a href= ' javascript:wsx (\" 1\ ") ' >{$this->config[" First "]}</a>&nbsp;";
$str. = "<a href= ' javascript:wsx (\" ". $this->page-1). " \ ") ' >{$this->config[" prev "]}</a>&nbsp;";
return $str;
}

  }
 
  /* The private method used inside the object to get the page number table information */
  private function PageList () {
     $linkPage = "&nbsp;<b>";
   
    $inum = Floor ($this->listnum/2);
   /* the list in front of the current page */
   for ($i = $inum; $i >= 1; $i-) {
    $ page = $this->page-$i;

    if ($page >= 1)
      $linkPage. = "<a href= ' javascript: WSX (\ "{$page}\") ' >{$page}</a>&nbsp; ';
   }
   /* information on current page */
   if ($this->pagenum > 1)
    $ Linkpage. = "<span style= ' padding:1px 2px;background: #BBB; Color:white ' >{$this->page}</span>& nbsp; ";
   
   /* the list following the current page */
   for ($i =1; $i <= $inum; $i + +) {
     $page = $this->page+ $i;
    if ($page <= $this->pagenum)
      $linkPage. = "<a href= ' javascript:wsx (\ "{$page}\") ' >{$page}</a>&nbsp; ';
    else
     break;
   }
    $linkPage. = ' </b> ';
   return $linkPage;
  }

/* Private method used inside the object to get operation information for the next and last page */
Private Function Nextlast () {
if ($this->page! = $this->pagenum) {
$str = "&nbsp;<a href= ' javascript:wsx (\" "). $this->page+1). " \ ") ' >{$this->config[" Next "]}</a>&nbsp;";
$str. = "&nbsp;<a href= ' javascript:wsx (\" ". $this->pagenum). " \ ") ' >{$this->config[" last "]}</a>&nbsp;";
return $str;
}
}

/* Private method used inside the object to display and process the form jump page */
Private Function Gopage () {
if ($this->pagenum > 1) {
/*return ' &nbsp;<input style= "width:20px;height:17px!important;height:18px;border:1px solid #CCCCCC;" Type= " Text "onkeydown=" Javascript:if (event.keycode==13) {var page= (this.value> '. $this->pagenum. ')? '. $this->pagenum ': this.value;location=\ '. $this->uri. ' Page=\ ' +page+\ '} "value=" '. $this->page. ' " >
<input style= "cursor:pointer;width:25px;height:18px;border:1px solid #CCCCCC;" type= "button" value= "GO" onclick= " Javascript:var page= (this.previoussibling.value> '. $this->pagenum. ')? '. $this->pagenum ': this.previoussibling.value;location=\ ' javascript:wsx ('. $this->uri. ' Page=\ ' +page+\ ') ' >&nbsp; '; */
Return ' &nbsp;<input id= ' Shuzi "style=" width:20px;height:17px!important;height:18px;border:1px solid #CCCCCC ; "type=" Text ">
<input style= "cursor:pointer;width:25px;height:18px;border:1px solid #CCCCCC;" type= "button" value= "GO" onclick= " WSX (0) ">&nbsp;";

}
}

/* Private method used inside the object to get the number of record bars displayed on this page */
Private Function Disnum () {
if ($this->total > 0) {
return $this->end ()-$this->start () +1;
}else{
return 0;
}
}
}



JS processing at the front desk is as follows:

<script type= "Text/javascript" >
$ (document). Ready (function (e) {
WSX ("1");
})
function wsx (n)
{//This paragraph does not have to be tube
if (n==0) {var shuzi=parseint ($ ("#shuzi"). Val ()), Var zyl=parseint ($ ("#zyl"). Text ()); if (Shuzi>zyl) {Shuzi=zyl;} N=shuzi;}
This is not a tube.
$.ajax ({
URL: "__CONTROLLER__/ZYMFF",
Data:{wurl:n},
Type: "POST",
DataType: "TEXT",
Success:function (data) {
var str= "<table width= ' 100% ' border= ' 1 ' cellpadding= ' 0 ' cellspacing= ' 0 ' ><tr><td> codename </td>< Td> name </td><td> parent code </td></tr> ";
var fen=data.split ("$");
var list=fen[0]; var fpage=fen[1];
var hang=list.split ("|");
for (i=0;i{
var dyg=hang[i].split ("^");
str+= "<tr><td>" +dyg[0]+ "</td><td>" +dyg[1]+ "</td><td>" +dyg[2]+ "</td> </tr> ";
}
$ ("#z1"). html (str);
$ ("#z2"). HTML (fpage);

}})}

In the background processing of the page, the return of Ajax select "eval", because the paging data and the paging information table will be returned all, so to spell string (with JSON should also line ...) Never tried)

 Public functionZhuyemian ()//Main Page Display    {            $this-display (); }     Public functionZYMFF ()//paging information and data processing{$wurl=$_post["Wurl"]; $u=m (' Chinastates '); $count=$u-Count(); $page=New\fenye\libs\page ($count, 25,$wurl); $list=$u->limit ($page->limit)Select (); $xinxi=$page-fpage (); foreach($list  as $v)            {                $str.=implode("^",$v); $str.="|"; }        $str=substr($str, 0,strlen($str)-1); $str.="$"; $str=$str.$xinxi; $this->ajaxreturn ($str, "eval"); }

Thinkphp 3.2 Ajax No refresh paging (not completely changed, temporary use)

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.