PDA

View Full Version : Getting difference between previous posted thread in same section.


3lou 55
11-12-2014, 11:28 AM
Hello,

I am creating a plugin that checks wether the user has already made a thread in the past 12 hours.
If they do, then don't allow them to make the thread.
All I need to know is how I would get the last inserted thread's time and then compare it to the actual time.
Is there anyone that can help me with this one?

Cheers,

kh99
11-12-2014, 11:46 AM
I think you could do a query like this:

$limit = 3600 * 12; // seconds in 12 hours
$result = $vbulletin->db->query_first("SELECT dateline FROM ".TABLE_PREFIX."thread WHERE postuserid = $userid ORDER BY dateline DESC");
if ($result && TIMENOW-$result['dateline'] < $limit)
{
// too soon
}


You could do it all in SQL by something like "WHERE UNIX_TIMESTAMP()-dateline < $limit", but this way if you want to display how long the user has to wait, you have the time of his last thread.