How to Design the previous and next articles of the current article?

Source: Internet
Author: User
On the view article details page, there is a link to the previous and next articles at the bottom. How do you implement this function? Generally, the document details are transmitted by passing the id in the past and reading the id record in the database. Therefore, id-1 or id + 1 cannot be used in the previous and next articles... on the view article details page,

At the bottom, there is a link to the previous and next articles,

How does one implement this function?

Generally, the details of an article are passed by an id,

Read this id record in the database,

The previous and next articles cannot be implemented using id-1 or id + 1,

Sometimes the Document id is not continuous, and a record will be deleted in some cases,

In this way, the id is not consecutive,

Therefore, the id-1 or id + 1 method is incorrect,

Do you have any other methods?

Reply content:

On the view article details page,

At the bottom, there is a link to the previous and next articles,

How does one implement this function?

Generally, the details of an article are passed by an id,

Read this id record in the database,

The previous and next articles cannot be implemented using id-1 or id + 1,

Sometimes the Document id is not continuous, and a record will be deleted in some cases,

In this way, the id is not consecutive,

Therefore, the id-1 or id + 1 method is incorrect,

Do you have any other methods?

$sql = '(select id,title from articles where id < :id order by id desc limit 1) union all (select id,title from articles where id > :id order by id asc limit 1)';

Mysql:select id from table where id>10 order by id desc limit 1

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.