MyBB Community Forums

Full Version: Make this query fetch threads that are 24h old???
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please help me, how to make this query fetch only threads that are =< 24h old. Only that are less than 24h old,

$max = 5;
	   $query = $db->query("
		SELECT t.*, u.username, f.*, p.displaystyle AS threadprefix
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
		INNER JOIN ".TABLE_PREFIX."forums f
	   ON (f.fid = t.fid)
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
		WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
		ORDER BY t.lastpost DESC LIMIT $max");


What is I add to this query: t.dateline AS threaddate

if ($thread['threaddate'] =< 60*60*24*2); {
//do code
}
In your PHP code you will need to define the cutoff. The easiest way you can do this is
$cutoff = TIME_NOW - 86400;

Your query is mostly right, but instead of WHERE 1=1 you need to put t.dateline>$cutoff.
Thanks but could you please check my updated post

Thanks very much works great Smile
Quote:What is I add to this query: t.dateline AS threaddate

There really is no reason to use an alias on the column. It just makes things more complicated than they need to be.

I also heavily advise against this in your PHP code
if ($thread['threaddate'] =< 60*60*24*2); {
//do code
} 

The if statement is a syntax error because an if statement doesn't end with a semicolon. The bigger issue though is if you don't use the dateline field in your query, you'll be searching through many more records which is bad for performance reasons.