我想計算兩個成員之間的會話數。 當用戶1訪問用戶2的配置文件時,我看到可見的結果。但是,當用戶2訪問配置文件1時,我沒有結果。rowCount where和OR與MySQL和PHP
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();
}
'WHERE(發件人=和接收器=?) 或' – JYoThI
另外,你要互換的發送者和接收者的兩倍(接收器=和發件人=?):在查詢和在數組中。淨結果:根本沒有交換,並且重複子句'WHERE(sender = $ sender AND receiver = $ receiver)OR(receiver = $ receiver AND sender = $ sender)' – bracco23
我認爲在這種情況下括號不是問題 – etsa