In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use simple PHP pagination". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Method 1:
The copy code is as follows:
Method 2:
The copy code is as follows:
How to use it:
$curPage=$_GET ['cp']
$curPageGroup=$_GET ['cpg']
If ($curPage== "")
$curPage=1
If ($curPageGroup== "")
$curPageGroup=1
/ / all starts from 1. Before that, the incoming data should be verified to prevent injection.
/ / .
$pager=new MysqlPager ()
$pager- > initAllVar (...)
$pager- > showNavPager ()
/ / the following SQL can be any output
$sql= "select id form dbname"
$querysql=$pager- > getQuerySqlStr ($sql)
/ / after querying the database with $querysql, you can get the corresponding result set.
Method 3:
PHP paging function:
The copy code is as follows:
< ? //为了避免重复包含文件而造成错误, 加了判断函数是否存在的条件: if(!function_exists(pageft)){ //定义函数pageft(),三个参数的含义为: //$totle:信息总数; //$displaypg:每页显示信息数,这里设置为默认是20; //$url:分页导航中的链接,除了加入不同的查询信息 "page"外的部分都与这个URL相同。 //默认值本该设为本页URL(即$_SERVER["REQUEST_URI"]) ,但设置默认值的右边只能为常量,所以该默认值设为空字符串 ,在函数内部再设置为本页URL。 function pageft($totle,$displaypg=20,$url="){ //定义几个全局变量: //$page:当前页码; //$firstcount:(数据库)查询的起始项; //$pagenav:页面导航条代码,函数内部并没有将它输出; //$_SERVER:读取本页URL"$_SERVER["REQUEST_URI"]"所必须。 global $page,$firstcount,$pagenav,$_SERVER; //为使函数外部可以访问这里的"$displaypg", 将它也设为全局变量。注意一个变量重新定 义为全局变量后,原值被覆盖,所以这里给它重新赋值。 $GLOBALS["displaypg"]=$displaypg; if(!$page) $page=1; //如果$url使用默认,即空值,则赋值为本页URL: if(!$url){ $url=$_SERVER["REQUEST_URI"];} //URL分析: $parse_urlparse_url=parse_url($url); $url_query=$parse_url["query"]; //单独取出URL的查询字串 if($url_query){ //因为URL中可能包含了页码信息,我们要把它去掉, 以便加入新的页码信息。 //这里用到了正则表达式,请参考"PHP中的正规表达式" $url_query=ereg_replace("(^|&)page=$page","",$url_query); //将处理后的URL的查询字串替换原来的URL的查询字串: $url=str_replace($parse_url["query"],$url_query,$url); //在URL后加page查询信息,但待赋值: if($url_query) $url.="&page"; else $url.="page"; }else { $url.="?page"; } $lastpg=ceil($totle/$displaypg); //最后页,也是总页数 $page=min($lastpg,$page); $prepg=$page-1; //上一页 $nextpg=($page==$lastpg ? 0 : $page+1); //下一页 $firstcount=($page-1)*$displaypg; //开始分页导航条代码: $pagenav="显示第 < B>"($totle? ($firstcount+1): 0)."
< /B>-
< B>".min ($firstcount+$displaypg,$totle)."
< /B>A total of $totle records
< BR>"
/ / if there is only one page, jump out of the function:
If ($lastpg
The pageft () function is called when paging. But it doesn't output anything, but produces several global variables for use: $firstcount, $displaypg, $pagenav.
The following example illustrates the use of the PHP paging function:
The copy code is as follows:
< ? //(前面程序略) include("pageft.php"); //包含"pageft.php"文件 //取得总信息数 $result=mysql_query("select * from mytable"); $total=mysql_num_rows($result); //调用pageft(),每页显示10条信息 (使用默认的20时,可以省略此参数), 使用本页URL(默认,所以省略掉)。 pageft($total,10); //现在产生的全局变量就派上用场了: $result=mysql_query("select * from mytable limit $firstcount, $displaypg "); while($row=mysql_fetch_array($result)){ //(列表内容略) } //输出分页导航条代码: echo $pagenav; //(后面程序略) ?>This is the end of "how to use simple PHP pagination". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.