Php: how to get the previous and next pages of an article _ PHP Tutorial

Source: Internet
Author: User
Php retrieves the previous and next pages of an article. Php: how to obtain the previous and next pages of an article. This document describes how to obtain an article by using php. Share it with you for your reference. The specific method is as follows: today I found a site asking php to obtain the previous and next pages of the article.
The example in this article describes how to get an article from php. Share it with you for your reference. The specific method is as follows:

I found a problem with a website today. I went directly to the latest article published on this channel. The principle should be that the first and last IDs of the article ID are the top and bottom pages, the following is a detailed description.

Let's take a look at the example below: 1, 2, 3, 4, 5.

If the five above are IDs, the order we want to use order by ID asc should be 4. The principle is so simple.

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 a previously written 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 "". $ rs ['title']. "";
}
Else
{
Return 'no longer ';
}
}

Examples in this article describe how php gets an article. Share it with you for your reference. The specific method is as follows: I found a question on a station today...

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.