How PHP Gets the previous page and next page of the article

Source: Internet
Author: User

This article is an example of how PHP gets the article. Share to everyone for your reference. Here's how:

Today found a station problem, is directly to the latest release of the channel, according to the principle should be the ID of the article itself before and after the ID is the next page, let me tell you in detail.

Let's look at an example: 1,2,3,4,5.

If the above 5 is ID, I want to use ORDER by ID ASC to get the sort should be, 4, good principle is so simple.

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 results are the same as we thought, okay. Finally, I will share my previous function with you, 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< $fid order BY id desc limit 1";
}
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 "<a href=" ". $rs [' S_url ']." " > ". $rs [' title ']." </a> ";
}
Else
{
Return ' no ';
}
}

How PHP Gets the previous page and next page of the article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.