Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement the previous page and the next page by php

Shulou Source: shulou.com Published: 2022-06-02 09:16:00 09月11日 Update

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!

Tags: Previous methods problems code content functions ascending order more examples articles helpless for this examples functions foreground reasons principles parameters examples examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Technology Linux vpn macOS