Hi guys,
I am trying to figure out how to do the following
I want to get the last 3 entries in the database
get the time, then i need to find out if all 3 of them have been added in the last 3minutes.
If anyone can help that would be great.
Thanks
Hi guys,
I am trying to figure out how to do the following
I want to get the last 3 entries in the database
get the time, then i need to find out if all 3 of them have been added in the last 3minutes.
If anyone can help that would be great.
Thanks
Hi Russell, Assuming that
Hi Russell,
Assuming that your tables have a `created` field containing a standard PHP time() value; you can select ordering on that field (descending), limit to 3, then you just need to look at the last result returned and compare to time()-3 minutes. For example:
$result = mysql_query("SELECT timestamp FROM table ORDER BY created DESC LIMIT 3");$rows = array();
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$rows[] = $row;
}
if ($rows[2]["created"] > (time()-180))
{
// here if all of the last 3 rows added in the last 3 minutes (180 seconds)
}
else
{
// here if not
}
Hope this helps!
Cheers,
David.