Home  >  Article  >  Web Front-end  >  Simple implementation of Ajax non-refresh paging effect

Simple implementation of Ajax non-refresh paging effect

韦小宝
韦小宝Original
2018-01-01 19:40:171889browse

This article mainly introduces in detail the code to simply implement the Ajax non-refresh paging effect. It has certain reference and value for learning ajax. Friends who are interested in ajax can refer to it

Ajax No refresh paging effect, the following code implements





 
 Ajax无刷新分页效果

 

Ajax无刷新分页效果


The paging code found online, can be used for personal testing~


/*
* Created on 2011-07-28
* Author : LKK , http://lianq.net
* 使用方法:
require_once('mypage.php');
$result=mysql_query("select * from mytable", $myconn);
$total=mysql_num_rows($result); //取得信息总数
pagepide($total,10); //调用分页函数

//数据库操作
$result=mysql_query("select * from mytable limit $sqlfirst,$shownu", $myconn);
while($row=mysql_fetch_array($result)){
...您的操作
}
echo $pagecon; //输出分页导航内容
*/

//if(!function_exists("pagepide")){
#$total 信息总数
#$shownu 显示数量,默认20
#$url 本页链接
 function pagepide($total,$shownu=20,$url=''){

#$page 当前页码
#$sqlfirst mysql数据库起始项
#$pagecon 分页导航内容
 global $page,$sqlfirst,$pagecon,$_SERVER;
 $GLOBALS["shownu"]=$shownu;

 if(isset($_GET['page'])){
  $page=$_GET['page'];
 }else $page=1;

#如果$url使用默认,即空值,则赋值为本页URL
 if(!$url){ $url=$_SERVER["REQUEST_URI"];}

#URL分析
 $parse_url=parse_url($url);
 @$url_query=$parse_url["query"]; //取出在问号?之后内容
 if($url_query){
  $url_query=preg_replace("/(&?)(page=$page)/","",$url_query);
  $url = str_replace($parse_url["query"],$url_query,$url);
  if($url_query){
  $url .= "&page";
  }else $url .= "page";
 }else $url .= "?page";

#页码计算
 $lastpg=ceil($total/$shownu); //最后页,总页数
 $page=min($lastpg,$page);
 $prepg=$page-1; //上一页
 $nextpg=($page==$lastpg ? 0 : $page+1); //下一页
 $sqlfirst=($page-1)*$shownu;

#开始分页导航内容
 $pagecon = "显示第 ".($total?($sqlfirst+1):0)."-".min($sqlfirst+$shownu,$total)." 条记录,共 $total 条记录";
 if($lastpg<=1) return false; //如果只有一页则跳出

// if($page!=1) $pagecon .=" 首页 "; else $pagecon .=" 首页 ";
// if($prepg) $pagecon .=" 前页 "; else $pagecon .=" 前页 ";
// if($nextpg) $pagecon .=" 后页 "; else $pagecon .=" 后页 ";
// if($page!=$lastpg) $pagecon.=" 尾页 "; else $pagecon .=" 尾页 ";

 if($page!=1) $pagecon .=" 首页 "; else $pagecon .=" 首页 ";
 if($prepg) $pagecon .=" 前页 "; else $pagecon .=" 前页 ";
 if($nextpg) $pagecon .=" 后页 "; else $pagecon .=" 后页 ";
 if($page!=$lastpg) $pagecon.=" 尾页 "; else $pagecon .=" 尾页 ";

#下拉跳转列表,循环列出所有页码
// $pagecon .=" 到第 \n";
 for($i=1;$i<=$lastpg;$i++){
  if($i==$page) $pagecon .="\n";
  else $pagecon .="\n";
 }
 $pagecon .=" 页,共 $lastpg 页";

 return $page;
 }
//}else die('pagepide()同名函数已经存在!');


The following is a simple paging display I made



 table{width:500px;margin:auto;border: 1px solid black; border-collapse:collapse;text-align:center;}
 td{border: 1px solid black;}
 
 
eof;

 $num = ($page - 1) * $per;
// foreach ($goods as $k => $v) {
 while($goods = mysqli_fetch_assoc($result)){
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 }

 echo "";
 echo "
序号商品编号商品类型
".++$num."$goods[cat_id]$goods[cat_name]
$pagecon
";


Simple implementation of Ajax non-refresh paging effect

The page will not refresh and jump, the URL will not change, you can see the data interaction of the website

Simple implementation of Ajax non-refresh paging effect

The above is this article All the contents, I hope it will be helpful to everyone's learning, and I also hope that everyone will support the PHP Chinese website.

Related recommendations:

How to implement the Ajax upload image and preview function

A simple method for Ajax asynchronous downloading of files

AJAX checks whether the username is unique

The above is the detailed content of Simple implementation of Ajax non-refresh paging effect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn