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
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

Link to comment
Share on other sites

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 = .

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.