PHP get Article previous page and next page method, _php tutorial

Source: Internet
Author: User

PHP gets the article previous page and next page method,


This article explains how PHP gets the previous page and the next page of the article. Share to everyone for your reference. Here's how:

Today found a station of the previous page and the next page, there is no problem but the next page is directly to the latest published articles on this 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 the ID, I want to sort the previous page directly using the ORDER by id DESC, such as my current ID is 3 then out of 2 is right, on the next page we want to use the order by ID ASC to get the sort should be, 4, good principle is so simple.

SQL implementation method, the code is as follows:

Previous: copy code code as follows: $sql = "select field from table name where id<3 ORDER BY id desc limit 1";

Next: Copy the code code 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:
Copy the Code Code as follows:/*
Previous page, next page
int $tag 0 prev, 1 next
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 "". $rs [' title ']. "";
}
Else
{
Return ' no ';
}
}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/920627.html www.bkjia.com true http://www.bkjia.com/PHPjc/920627.html techarticle PHP Gets the previous page and the next page of the article method, this article describes how PHP gets the article previous page and next page method. Share to everyone for your reference. The specific method is as follows: Today hair ...

  • 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.