Php implements the next page of the previous article

Source: Internet
Author: User
Today, I found that there was a problem with the previous and next pages of this site. the previous page was okay, but on the next page, I directly posted the latest article on this channel, the principle should be that the previous and subsequent IDs of the article itself are the top and bottom pages. I will introduce them to you in detail below. first look at an example: 1... today, I found that there was a problem with the previous and next pages of this site. the previous page was okay, but on the next page, I directly posted the latest article on this channel, the principle should be that the previous and subsequent IDs of the article itself are the top and bottom pages. I will introduce them to you in detail below.

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

If the five above are IDs, I want to sort the previous pages directly using order by ID desc. if my current id is 3, then the result is 2, for the next page, the order we use order by id asc should be 4. The principle is so simple.

The code is as follows:

Previous Page: $ SQL = "Select field from table name where id <3 order by id desc limit 1 ";

Next Page: $ 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:

/* Previous page, next page int $ tag 0 previous page, 1 Next Page int $ fid www.phprm.com */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 ';}}

Address:

Reprinted at will, but please attach the article address :-)

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.