-1
$result = mysqli_query($con, "SELECT * FROM queue_stats
WHERE qevent = 11 AND 'datetime' < NOW() LIMIT 20");

I have a table column called 'datetime' with date format(YYYY-MM-DD H:M:S) And I want to get 20 query results with dates before now, i.e. the time the query was made. How can I make the 'datetime' < NOW() produce the required result. When I use this mysql statement, I always get a blank page with no result. Please help.

2 Answers2

1

Single quotes (') denote string literals. Thus you're comparing the string 'datetime' to the result of now() implicitly converted to a string. You probably meant to use backticks to escape the column name:

SELECT * 
FROM   queue_stats
WHERE  qevent = 11 AND `datetime` < NOW() 
       -- Here --------^--------^
LIMIT  20
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

change single quote to apostrophe

 $result = mysqli_query($con, "SELECT * FROM queue_stats WHERE qevent = 11 AND `datetime` < NOW() LIMIT 20");
Beginner
  • 4,118
  • 3
  • 17
  • 26