drf21989 2012-03-18 11:22
浏览 12
已采纳

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

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?

Basically how my site is set up is I've got a Twitter-esque blog page. 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. 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

  • 写回答

1条回答 默认 最新

  • dongzhang5006 2012-03-18 11:27
    关注

    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.

    $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)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算