Thursday, 12 September 2013

SQL statement won't limit. Show's no results

SQL statement won't limit. Show's no results

I'm creating a web app and I'm trying to limit the number of results that
come in. When I do the query all the results come back but if I put LIMIT
5 at the end of the statement, then no results come back. Here is my code:
$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'];
Any clues as to why it's not working?

No comments:

Post a Comment