urber
urber

Reputation: 13

Get mysql data older than 5 minutes php

I have search and tried most of the answers and still could not work with my code. I need help with this not sure where is wrong. I insert timeon with $date = current_time( 'mysql' );

My sql table online

ID  int(11)         
onlineppl   varchar(255)    
timeon  datetime    

data:
ID  onlineppl   timeon
18  1           2014-09-23 12:49:57
17  3           2014-09-23 12:45:00
16  12          2014-09-23 12:44:56

$result = mysql_query("SELECT * FROM online WHERE timeon < DATE_SUB(NOW(),INTERVAL 5 MINUTE)");
$row = mysql_fetch_array($result);


echo $row['onlineppl'];

I get no result... need help thanks.

Upvotes: 1

Views: 908

Answers (2)

Nikhil Vaghela
Nikhil Vaghela

Reputation: 222

not less then use greater then

 SELECT * FROM online WHERE timeon > (NOW() - INTERVAL 5 MINUTE);

it's working use (>=)

Upvotes: 0

Jenz
Jenz

Reputation: 8369

Change your query to

SELECT * FROM online WHERE timeon < (NOW() - INTERVAL 5 MINUTE);

Upvotes: 1

Related Questions