Php+ajax implement no refresh paging, Phpajax Refresh page _php Tutorial

Source: Internet
Author: User

Php+ajax implement no refresh paging, Phpajax Refresh page


This paper describes the implementation method of Php+ajax implementation without refresh. Share to everyone for your reference. Specific as follows:

Limit offset, length;
Limit 0, 7; First page
Limit 7, 7; Second page
Limit 14, 7; Third page
Number of messages per page: 7
Information total number of bars: SELECT COUNT (*) from table
Total Pages: Ceil rounding up (total number of bars/pages per page)
1. Specific use of pagination class

<?phpclass pagination {private $total;//The total number of records in the data table private $listRows;//page shows the number of rows private $limit; limit PR for//mysql database Ivate $uri; The URI address in front of the paging information is private $pageNum; Number of pages Private $config = Array (' header ' = ' record ', ' prev ' + ' "" "prev", "Next" = "Next" "," "First" = "" Home "", "la  St "=" "Last" ");  Private $listNum = 8; /* * $total Total number of current information * $listRows number of bars displayed per page * $pa the page http//URL/index.php?page=5 */Public function __construc    T ($total, $listRows = ten, $pa = "") {$this->total = $total;    $this->listrows = $listRows;    $this->uri = $this->geturi ($PA); $this->page =!empty ($_get["page"])?    $_get["page"]: 1;//does not pass in the page, the default display first page $this->pagenum = ceil ($this->total/$this->listrows);  $this->limit = $this->setlimit (); }//Set the number of bars displayed per page private function Setlimit () {return ' Limit '. ($this->page-1) * $this->listrows.  ", {$this->listrows}"; }//Get the URL address 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;    }//Magic method, Public function __get ($args) {if ($args = = "Limit") return $this->limit;  else return null;    }//page start of the number of private function start () {if ($this->total = = 0) return 0;  else return ($this->page-1) * $this->listrows + 1;  }//The number of bars at the end of the page private Function end () {return min ($this->page * $this->listrows, $this->total);    }/* Set homepage */Private Function First () {$html = ""; if ($this->page = = 1) $html. = ". $this->config[" First "]. '    ';      else $html. = "uri}&page=1\") ' >{$this->config["First"} ";    $html. = "Uri}&page=1 ' >{$this->config[" First "]}";  return $html; }/* Set previous page */Private Function prev () {    $html = ""; if ($this->page = = 1) $html. = ". $this->config[" prev "]. '    '; else $html. = "Uri}&page=". ($this->page-1).      "\") ' >{$this->config["prev"} "; $html. = "Uri}&page=". ($this->page-1). "'    >{$this->config["prev"} ";  return $html;    }//Page list "Home" "2" "3" ... "Last" 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;    }/* Set next page */Private function Next () {$html = ""; if ($this->page = = $this->pagenum) $html. = ". $this->config[" Next "]. ' ';   else $html. = "Uri}&page=". ($this->page + 1).      "\") ' >{$this->config["Next"} "; $html. = "Uri}&page=". ($this->page + 1). "'    >{$this->config["Next"} ";  return $html;    }/* Set end */Private function last () {$html = ""; if ($this->page = = $this->pagenum) $html. = ". $this->config[" Last "]. '    '; else $html. = "Uri}&page=". ($this->pagenum).      "\") ' >{$this->config["Last"} "; $html. = "uri}&page=. (this->pagenum). '    >{$this->config["Last"]} ";  return $html;  }/* Settings page Jump */Private Function Gopage () {return '    '; }//Page list configuration options function fpage ($display = Array (0, 1, 2, 3, 4, 5, 6, 7, 8)) {$html [0] = "Total{$this->total}{$this->config["header"]}    "; $html [1] = "per page display" . ($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; }}

2 Data display

<?php//link Database//Get specific information//pagination display header ("Content-type:text/html;charset=utf-8"); $link = mysql_connect (' localhost ', ' Root ', ' 111111 '); mysql_select_db (' Shop ', $link); mysql_query ("Set names UTF8"); $css = <<
 
  Table {border:1px solid black; width:700px; margin:auto; border-collapse:collapse;} TD {BORDER:1PX solid black;}Eof;echo $css, echo "
  
 ";//1 introduces pagination class include"./pagination.php ";//2. Total number of information obtained $sql = "SELECT * from Sw_goods"; $qry = mysql_query ($sql); $total = Mysql_num_rows ($qry); $per = 7;//3. Instantiate the paging class object $page_obj = new Pagination ($total, $per);//4. Assemble SQL statements to get each page of information//use page_obj to achieve limit flexible settings//$page _obj, limit; $sqla = "SELECT * from Sw_goods". $page _obj->limit;$ Qrya = mysql_query ($sqla);//5. Get a list of pages $pagelist = $page _obj, fpage (3,4,5,6,7,8), $i =1;while ($rsta = Mysql_fetch_assoc ($qrya)) {echo] 
   
     "; echo " 
    "; echo " 
    "; echo " 
    "; echo " 
    "; echo " 
    "; echo " 
   ";} echo " 
   "; Echo" 
  
Serial number Name Number Price Time
". $i + +."". $rsta [' Goods_name ']."". $rsta [' Goods_number ']."". $rsta [' Goods_price ']."". Date (" Y-m-d h:i:s ", $rsta [' Goods_create_time '])."
". $pagelist."
";

3 Ajax No-refresh paging implementation

Open (' get ', ' http//url/index.php?page=2 ')

      New Web page    
 
      
 
      
 
                  

Ajax no Refresh page-out effect

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1073128.html www.bkjia.com true http://www.bkjia.com/PHPjc/1073128.html techarticle Php+ajax Implement no refresh paging, Phpajax refresh pagination This article describes the Php+ajax implementation of non-refreshed paging implementation method. Share to everyone for your reference. As follows: Limit offset, ...

  • Related Article

    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.