SQL statement - please help
| From: | Jacques | Date: | Thu, 24 Mar 2005 08:50:38 +0000 |
| Subject: | SQL statement - please help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-211439@lists.php.net to get a copy of this message | ||
Dear all
Please, I realy need your help. I am trying to extract only those records
that were entered during the past hour from my MySQL database. The
following SQL statement extracts all the records. As soon as I change the
INTERVAL to 1 HOUR I see all the records in my database. When I change
CURDATE() to CURTIME() no records are extracted from the database. The
cgtimeposted field is a time data type.
Please advise me as to how I can formulate my SQL statement so that only
those records entered within the past hour displays on my page.
Here is my current SQL statement - this statement displays all the records:
$sql = "Select tblchatglobal.cgid, tblchatglobal.cgdateposted,
tblchatglobal.cgtimeposted, tblchatglobal.uid, tblchatglobal.cgmsg,
tblusers.uid, tblusers.uusername from tblchatglobal, tblusers where
(tblchatglobal.uid = tblusers.uid) and (DATE_SUB(CURDATE(),INTERVAL 1 HOUR)
<= tblchatglobal.cgtimeposted) order by tblchatglobal.cgtimeposted desc";
Jacques