Web アプリを作成していて、受信する結果の数を制限しようとしています。クエリを実行するとすべての結果が返されますが、ステートメントの最後に LIMIT 5 を配置すると、結果が返されません. これが私のコードです:
$query = $conn->prepare('SELECT * FROM notifications WHERE (needs=:username OR worker=:username) ORDER BY CASE WHEN needs=:username THEN needsread ELSE workerread END, time DESC LIMIT 5');
$query->bindParam(':username', $username);
$query->execute();
echo "<div id='notes_title' style='background-color: #333333; padding: 10px; text-align: center; font-weight: lighter; letter-spacing: 1px;'>Notes</div>";
$te = 0;
while ($rows = $query->fetch()) {
$needs = $rows['needs'];
$id = $rows['ID'];
$worker = $rows['worker'];
$title = $rows['title'];
$needsread = $rows['needsread'];
$workerread = $rows['workerread'];
$time = $rows['time'];
$type = $rows['type'];
なぜそれが機能しないのかについての手がかりはありますか?