简体   繁体   English

如果没有更多条目要加载,在mysql查询中添加if语句?

[英]Adding an if statement in mysql queries if there are no more entries to load?

sorry for the convoluted question. 对于这个令人困惑的问题,我们深表歉意。 The issue I'm having is is there a way to add a conditional in the form of an if statement or similar function to check if when a mysql query is run, if there aren't any rows/data entries left? 我遇到的问题是有没有一种方法可以以if语句或类似函数的形式添加条件,以检查是否在运行mysql查询时是否还没有行/数据条目?

Basically how my site is set up is I've got a Twitter-esque blog page. 基本上,我的网站是如何设置的,我拥有一个类似Twitter的博客页面。 On the site is displayed a bunch of posts descending by date added, which are all taken from a database. 在网站上显示了一堆按照添加日期降序排列的帖子,这些帖子均取自数据库。 By default the page starts off displaying only 8 posts, with a "Click for more" button which then runs an Ajax function, loading in 5 more database entries, which you can keep clicking to load in more posts. 默认情况下,该页面开始时仅显示8个帖子,并带有“单击更多”按钮,然后该按钮运行Ajax函数,并加载5个其他数据库条目,您可以继续单击以加载更多帖子。 Is there any way to check if there aren't any more data entries available? 有什么方法可以检查是否没有其他可用的数据条目? Basically what I want to do is have the "click for more" button to disappear when all of the database entries have been displayed/queried. 基本上,我想做的是在所有数据库条目都已显示/查询后消失的“单击更多”按钮。

Searching around hasn't done me any good, thanks for any help! 到处搜索并没有给我带来任何好处,谢谢您的帮助! :D :D

Do something like this (Note this is untidy, but it's simply an example): 做这样的事情(注意这是不整洁的,但这只是一个例子):

I'm assuming you're using PHP and AJAX to fetch new posts. 我假设您正在使用PHP和AJAX来获取新帖子。

$nPosts = mysql_query("SELECT COUNT(ID or whatever your auto-increment field is called) FROM Posts");

$nPosts = mysql_fetch_array($nPosts);


if ($nPosts[0] == $postsThatAreBeingDisplayed)
{
    (Tell AJAX to disable the button)
}
else
{
    (Pass AJAX back 5 more posts)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM