简体   繁体   English

如何在PDO中正确计算查询

[英]How to properly count a query in pdo

I am trying to dynamically load more posts into my system 我正在尝试将更多帖子动态加载到我的系统中

This is my code... 这是我的代码...

$stmt = "
  SELECT * FROM `acmPosting` 
  WHERE (`sender`='$thisID' AND `postType`='a')
  OR (`recip`='$thisID' AND `sender`='$userID' AND `postType`='a')
  OR (`sender` IN ($friendsArray) AND `recip`='$thisID'  AND `postType`='a')
  ORDER BY `timeSent` DESC LIMIT $startlimit,10";

    if($stmtCount = $conn->query($stmt)){
        if($stmtCount->fetchColumn() > 0){
            $result = acmPosts($conn, $site, $userID, $stmt);
            $jsonArray['a'] = $result;
            $jsonArray['b'] = 'go';             
        }else{
            $jsonArray['a'] = '<div class="thisOutput" style="padding:12px;">There are no more posts</div>';
            $jsonArray['b'] = 'stop';
        }
    }

Everything works fine until it gets to the last set of posts AKA if the LIMIT is 100,10 but there are 105 posts in the call it won't call any to the fetchColumn(). 直到它到达最后一组职位的AKA如果限制100,10但也有105个职位的通话也不会调用任何的fetchColumn(),一切工作正常。

I hope this question makes sense. 我希望这个问题有意义。 Thanks in advance for any help you can give. 在此先感谢您提供的任何帮助。

EDIT 编辑

How can I determine when I have reached the LIMIT and act accordingly 如何确定何时达到极限并采取相应措施

Your description is not very precise but maybe this is what you are looking for: 您的描述不是很准确,但是也许这是您想要的:

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows http://dev.mysql.com/doc/refman/5.0/zh-CN/information-functions.html#function_found-rows

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

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