Query not Echoing Out
The code below should echo out the total number of messages less than 24 hours old where recipient = '$u'
, but it doesn't seem to be working. Any idea why not?
Thanks in advance,
John
$sqlStrw = "SELECT COUNT(*) newmessages
FROM PRIVATEMESSAGE pm
WHERE pm.datesent >= DATE_SUB(NOW(), INTERVAL 1 DAY)
AND recipient = '$u'";
$resultw = mysql_query($sqlStrw);
$arrw = array();
echo "<table class=\"samplesrecw\">";
while ($roww = mysql_fetch_array($resultw)) {
echo '<tr>';
echo '<td style="border:5px solid #FF8F20;" class="sitename5pw">'.$roww["newmessages"].'new1</td>';
echo '</开发者_运维知识库tr>';
}
echo "</table>";
I think there's a slight error in your original query. You're missing the "AS" from the top line so the row won't be pulling as you expect, it should look like this:
$sqlStrw = "SELECT COUNT(*) AS newmessages
FROM PRIVATEMESSAGE pm
WHERE pm.datesent >= DATE_SUB(NOW(), INTERVAL 1 DAY)
AND recipient = '$u'";
Best thing to do when these queries don't work is use something like phpMyAdmin to test the query and see what results are being returned.
精彩评论