Home > Backend Development > PHP Tutorial > How to get the previous page and next page of an article in php_PHP tutorial

How to get the previous page and next page of an article in php_PHP tutorial

WBOY
Release: 2016-07-13 10:09:50
Original
964 people have browsed it

How to get the previous page and next page of an article in php

The example in this article describes how to obtain articles in php. Share it with everyone for your reference. The specific methods are as follows:

Today I found a problem with a website, which went directly to the latest article published on this channel. According to the principle, the ID before and after the article itself should be 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 want to use order by id asc to get the order, 4, well the principle is as simple as that.

SQL implementation method, the code is as follows:

:

The code is as follows: $sql ="Select field from table name where id>3 order by id asc limit 1";

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:

The code is as follows: /*

int $tag 0
int $fid
*/
function nextPre($tag=0,$zid,$fid)
{
if( $tag )
{
$sql ="Select field from table name where id }
else
{
$sql ="Select field from table name where id>$fid order by id asc limit 1";
}
//$sql = "Select * from table name where order by id desc limit 0,10";
$result = mysql_query($sql) or die('query error');
if( mysql_num_rows( $result ) )
{
$rs = mysql_fetch_array( $result );
return "".$rs['title']."";
}
else
{
return 'No more';
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/941967.htmlTechArticleHow to get the previous page and next page of the article in php. This article describes the method of getting the article in php. Share it with everyone for your reference. The specific method is as follows: Today I found a problem with a website...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template