Jump to content

Find All Posts From Last 24 Hours


dachshund

Recommended Posts

Hi,

 

I'm trying to find all the MySQL entries from the last 24 hours. So far I have this. I just don't know how to take 1 day off the current time.

 

$lastday = date('Y-m-d h:i:s');

$sql = "SELECT * FROM content WHERE `live` LIKE '0' AND `date` >= '$lastday' ORDER BY date DESC LIMIT 40";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){

 

Thanks in advance,

 

Jack

Link to comment
https://forums.phpfreaks.com/topic/270942-find-all-posts-from-last-24-hours/
Share on other sites

The 24 hours before will be a dynamic value so it would have to find out on exercution.....

 

[color=#000000][color=#0000BB]<?php [/color][/color]
$24HoursAgo = $currentTime-3600*24
[color=#000000][color=#007700]?>[/color][/color]

 

myslq..

SELECT *
FROM content
WHERE `live`
LIKE '0'
AND  time   !>  '$24hoursago'
ORDER BY date
DESC LIMIT 40

Yes, your post. 

 

What the OP asked for can be done entirely in MySQL, and probably should be. Furthermore, your query uses !> which is invalid syntax. You also used the wrong column name. 

 

OP: As an aside, there's no obvious reason to use LIKE on the live column, just compare it with = .

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.