php实现上一篇下一篇的方法总结
php实现上一篇下一篇这个主要是通过sql来根据当前的id来进行判断然后筛选出当前ID之前的数据或ID之后的数据了就这么简单,具体的我们来看看。
实现网站文章里面上一篇和下一篇的sql语句的写法。
当前文章的id为 $article_id,当前文章对应分类的id是$cat_id,那么上一篇就应该是:
代码如下
SELECT max(article_id) FROM article WHERE article_id
执行这段sql语句后得到 $max_id,然后
SELECT article_id, title FROM article WHERE article_id = $max_id;
简化一下,转为子查询即:
SELECT article_id, title FROM article WHERE article_id = (SELECT max(article_id) FROM article WHERE article_id
下一篇为:
代码如下
SELECT min(article_id) FROM article WHERE article_id > $article_id AND cat_id=$cat_id;
执行这段sql语句后得到 $min_id,然后
SELECT article_id, title FROM article WHERE article_id = $min_id;
简化一下,转为子查询即:
代码如下
SELECT article_id, title FROM article WHERE article_id = (SELECT min(article_id) FROM article WHERE article_id > $article_id AND cat_id=$cat_id);
最后讲一下有很多朋友喜欢使用下面语句
上一篇:
代码如下
select id from table where id10 limit 0,1;
这样肯定没有问题,但是是性能感觉不怎么地。
sql语句优化
你可以使用union all来实现一条语句取3行数据,但是前提是3个查询的字段要相同
这个查询出来的结果第一行就是上一篇文章,第二行是当前文章,第三行是下一篇文章
代码如下
(select id from table where id 10 order by id desc limit 1);
现在来看一些cms中的例子phpcms 实现上一篇下一篇
获取当前浏览文章id
$id = isset($_GET['id']) > 0 ? intval($_GET['id']) : "";
下一篇文章
$query = mysql_query("SELECT id,title FROM article WHERE id>'$id' ORDER BY id ASC LIMIT 1");
$next = mysql_fetch_array($query);
上一篇文章
$query = mysql_query("SELECT id,title FROM article WHERE id $prev = mysql_fetch_array($query);
">?php>
">?php>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

If you find event ID 55, 50, 140 or 98 in the Event Viewer of Windows 11/10, or encounter an error that the disk file system structure is damaged and cannot be used, please follow the guide below to resolve the issue. What does Event 55, File system structure on disk corrupted and unusable mean? At session 55, the file system structure on the Ntfs disk is corrupted and unusable. Please run the chkMSK utility on the volume. When NTFS is unable to write data to the transaction log, an error with event ID 55 is triggered, which will cause NTFS to fail to complete the operation unable to write the transaction data. This error usually occurs when the file system is corrupted, possibly due to the presence of bad sectors on the disk or the file system's inadequacy of the disk subsystem.

When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

In Alibaba software, once you successfully register an account, the system will assign you a unique ID, which will serve as your identity on the platform. But for many users, they want to query their ID, but don't know how to do it. Then the editor of this website will bring you detailed introduction to the strategy steps below. I hope it can help you! Where can I find the answer to Alibaba ID: [Alibaba]-[My]. 1. First open the Alibaba software. After entering the homepage, we need to click [My] in the lower right corner; 2. Then after coming to the My page, we can see [id] at the top of the page; Alibaba Is the ID the same as Taobao? Alibaba ID and Taobao ID are different, but the two
![Event ID 4660: Object deleted [Fix]](https://img.php.cn/upload/article/000/887/227/168834320512143.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Some of our readers encountered event ID4660. They're often not sure what to do, so we explain it in this guide. Event ID 4660 is usually logged when an object is deleted, so we will also explore some practical ways to fix it on your computer. What is event ID4660? Event ID 4660 is related to objects in Active Directory and will be triggered by any of the following factors: Object Deletion – A security event with Event ID 4660 is logged whenever an object is deleted from Active Directory. Manual changes – Event ID 4660 may be generated when a user or administrator manually changes the permissions of an object. This can happen when changing permission settings, modifying access levels, or adding or removing people or groups

Where can I check the Tencent Video ID? There is an exclusive ID in the Tencent Video APP, but most users do not know how to check the Tencent Video ID. Next is the graphic tutorial on how to check the Tencent Video ID brought by the editor for users who are interested. Users come and take a look! Tencent Video Usage Tutorial Where to check Tencent Video ID 1. First open the Tencent Video APP and enter the special area through [Personal Center] in the lower right corner of the main page; 2. Then enter the Personal Center page and select the [Settings] function; 3. Then go to Settings page, click [Exit Account] at the bottom; 4. Finally, you can view the exclusive ID number on the page shown below.

Vue cannot obtain the id attribute because getElementById is used in the "created()" hook function, and Vue has not completed mounting; the solution is to "created() {let serachBox = document.getElementById('searchBox') ;...}" code can be migrated to the "mounted()" hook function.

How to hide the select element in jquery: 1. hide() method, introduce the jQuery library into the HTML page, you can use different selectors to hide the select element, the ID selector replaces the selectId with the ID of the select element you actually use; 2. css() method, use the ID selector to select the select element that needs to be hidden, use the css() method to set the display attribute to none, and replace selectId with the ID of the select element.

Asynchronous processing method of SelectChannelsGo concurrent programming using golang Introduction: Concurrent programming is an important area in modern software development, which can effectively improve the performance and responsiveness of applications. In the Go language, concurrent programming can be implemented simply and efficiently using Channels and Select statements. This article will introduce how to use golang for asynchronous processing methods of SelectChannelsGo concurrent programming, and provide specific
