Php+ajax No Refresh Paging instances detailed _php tips

Source: Internet
Author: User
Tags php programming prev

The example in this article describes the Php+ajax-no Refresh paging implementation method. Share to everyone for your reference, specific as follows:

The ajax_page_show_userinfo.php page is as follows:

<meta ' content:text/html;charset=utf-8 ' ></meta> <title>ajax pagination demo </title> <script language= "JavaScript" src= "Js/ajaxpage.js" ></script> <div id= "Result" > <?php $db =mysql_connect ("
LocalHost "," root "," 123456 ");
mysql_select_db ("register");
mysql_query ("Set names ' Utf-8 '");
$result =mysql_query ("SELECT * from user");
$total =mysql_num_rows ($result) or Die (Mysql_error ());
$page =isset ($_get[' page ')? Intval ($_get[' page '): 1;
$page _size=5;
$url = ' ajax_page_show_userinfo.php ';
$pagenum =ceil ($total/$page _size);
$page =min ($pagenum, $page);
$prepage = $page-1;
$nextpage = ($page = = $pagenum 0: $page + 1);
$pageset = ($page-1) * $page _size; $pagenav. = "Show First". ($total? ($pageset + 1): 0). " -". Min ($pageset +5, $total)." Records   Altogether <b> ". $total." </b> Records   is now  <b> ". $page."
</b>  page   ";
if ($page <=1) $pagenav. = "<a style=cursor:not-allowed;> home </a> "; else $pagenav. = "<a onclick=javascript:dopage (' result ', ' $url? page=1 ') style=cursor:pOinter;> home </a>  "; if ($prepage) $pagenav. = "<a onclick=javascript:dopage (' result ', ' $url? page= $prepage ') style=cursor:pointer;>
Prev </a>  ";
else $pagenav. = "<a style=cursor:not-allowed;> prev </a> "; if ($nextpage) $pagenav. = "<a onclick=javascript:dopage (' result ', ' $url? page= $nextpage ') style=cursor:pointer;
> next page </a>  ";
else $pagenav. = "<a style=cursor:not-allowed;> next page </a> "; if ($pagenum) $pagenav. = "<a onclick=javascript:dopage (' result ', ' $url? page= $pagenum ') style=cursor:pointer;>
Last </a>  ";
else $pagenav. = "<a style=cursor:not-allowed;> last </a> "; $pagenav. = "Total". $pagenum. "
Page ";
  if ($page > $pagenum) {echo "Error: no this page". $page;
Exit (); ?> <table align= "center" border= "2" width= "> <tr bgcolor=" #cccccc "align=" center "> <td> User name &l t;/td> <td> user Password </td> </tr> <?php $info =mysql_query ("SELECT * from User limit $pageset, $page _siz
E "); while ($arrAy=mysql_fetch_array ($info)) {?> <tr align= "center" > <td><?php echo $array [' username '];? ></td> <td><?php echo $array [' password '];?
></td> </tr> <?php}?> </table> <?php echo "<p align=center> $pagenav </p>"; ?> </div>

Ajaxpage.js under JS file:

var Http_request=false;
 function send_request (URL) {//initialization, specifying processing functions, sending the requested functions http_request=false; Starts initializing the XMLHttpRequest object if (window).
 XMLHttpRequest) {//mozilla browser http_request=new xmlhttprequest ();
 if (http_request.overridemimetype) {//Set MIME category Http_request.overridemimetype ("Text/xml"); ' Else if ' window.
 ActiveXObject) {//ie browser try{http_request=new activexobject ("msxml2.xmlhttp");
  }catch (e) {try{http_request=new ActiveXObject ("Microsoft.XMLHTTP"); }catch (e) {}} if (!http_request) {//exception, failed to create object instance Window.alert ("Failed to create XMLHTTP Object!")
 ");
 return false;
 } http_request.onreadystatechange=processrequest;
 Determine how to send the request, the URL, and whether to execute the next code http_request.open ("Get", url,true) synchronously;
Http_request.send (NULL); }//Processing return information function ProcessRequest () {if (http_request.readystate==4) {//Judging object state if (http_request.status==200) {//
 The information was successfully returned and the information Document.getelementbyidx (reobj) was processed. Innerhtml=http_request.responsetext; else{//page is not normal alert ("the page you requested is not normal!")
 "); }} function Dopage (obj,url) {//document.Getelementbyidx (obj). innerhtml= "reading data ...";
  Send_request (URL);
Reobj=obj;

 }

I hope this article will help you with your PHP programming.

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.