我想计算两个成员之间的对话次数。
当用户1访问用户2的个人资料时,我得到一个可见的结果。但是,当用户2访问配置文件1时,我没有结果。

public function getNumberConversations($sender, $receiver) {

    $st = Database::getDatabase()->prepare("SELECT id, sender, receiver
        FROM conversation
        WHERE sender = ? AND receiver = ?
        OR receiver = ? AND sender = ?
    ");

    $st->execute(array($sender, $receiver, $receiver, $sender));

    return $st->rowCount();

  }

最佳答案

我认为你应该改变

$st->execute(array($sender, $receiver, $receiver, $sender));




$st->execute(array($sender, $receiver, $sender, $receiver));


在您的情况下,括号可以(AND优先)

关于php - rowCount与MySQL和PHP在何处,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45813194/

10-11 06:29