Home >Backend Development >PHP Tutorial >How to get the previous page and next page of an article in php, _PHP tutorial
The example in this article describes the method of obtaining the previous page and next page of the article in PHP. Share it with everyone for your reference. The specific method is as follows:
Today I found a problem with the previous and next pages of a website. There was no problem with the previous page, but on the next page, I went directly to the latest article published by this channel. According to the principle, it should be before and after the ID of the article itself. ID is the upper and lower pages, let me tell you in detail below.
Let’s look at an example first: 1,2,3,4,5.
If the above 5 are IDs, I need to use order by id desc to sort the previous page. For example, if my current ID is 3, then the number that comes out is 2. For the next page, we need to use order by id asc. The resulting ranking should be 4. Well, the principle is that simple.
SQL implementation method, the code is as follows:
Previous page:
Next page:
The result is the same as what we thought. Finally, I will share with you a function I wrote before. The code is as follows:
I hope this article will be helpful to everyone’s PHP programming design.