In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Php how to achieve the previous page and the next page, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Php to achieve the previous page next page method: 1, create a PHP sample file; 2, through the "function GetPreNext ($gtype,$table,$catid,$id) {...}" method to display the previous article next article.
This article operating environment: windows7 system, PHP7.4 version, DELL G3 computer
How does php implement the previous page and the next page?
Example of simple implementation of previous page and next page by PHP
In this paper, an example is given to illustrate the simple realization of the function of the previous page and the next page by PHP.
The details are as follows:
Train of thought:
Now many people use id plus 1 and minus 1 to achieve the previous and next posts, but won't the article ID be broken? So you need to know how much the last ID and ID were OK.
Then how to solve this problem? it's very simple!
Example:
If the ID200 of this article
The previous article and the next article
If you are implementing the previous article, write the function on the action=up page.
$id= $_ GET ['id']; / / previous post: $sql= select * from article where id
< '.$id.' order by id desc limit 0,1';$rs= mysql_query($sql);$row= mysql_fetch_array ($rs);//下一篇:$sql= select * from article where id < '.$id.' order by id asc limit 0,1';$rs= mysql_query($sql);$row= mysql_fetch_array ($rs); 原理,查询比当前ID小(where id < '.$id.'上一篇)和比当前ID大(where id >'. $id.' 1 item (limit 0Power1) of the next article, and displayed in descending order (desc, previous article) and ascending order (asc, next article). When only one article is taken, descending order or ascending order can be omitted.
Specific implementation code: note that parameters need to be passed
The foreground is called at the previous post and the next post:
/ / display the previous next function GetPreNext ($gtype,$table,$catid,$id) {$preR=mysql_fetch_array (mysql_query ("select * from". $table. " Where catid= ". $catid." And id$id order by id asc limit 0d1 "); / / the most recent $next of id larger than the incoming id = (is_array ($nextR)?" Where id= {$nextR ['id']} ":' where 1 > 2'); $pre = (is_array ($preR)?" Where id= {$preR ['id']} ":' where 1 > 2'); $query =" Select * from ". $table."; $nextRow = mysql_query ($query.$next); $preRow = mysql_query ($query.$pre); if ($PreNext=mysql_fetch_array ($preRow)) {echo $PreNext ['pre'] =" previous post: ". $PreNext [' title']." } else {echo $PreNext ['pre'] = "previous post: no more";} if ($PreNext=mysql_fetch_array ($nextRow)) {echo $PreNext [' next'] = "next post:". $PreNext ['title']. ";} else {echo $PreNext [' next'] =" next post: no more ";}}
The code has been tested and available
After reading the above, have you mastered how php implements the previous page and the next page? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.