Just use the mysql time functions itself. You don’t even need to calculate the time in PHP:
$result = mysql_query("UPDATE novo_usuario SET validade=ADDTIME(NOW(),'0:05:00') WHERE ID=$id_user");
$result = mysql_query("SELECT * FROM novo_usuario WHERE validade>NOW()");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
...
Remember to use a column of the type datetime
(or even timestamp
) to store the time. I suggest not to use timestamp as a field name, not to be confused with the reserved word timestamp
.
Explanation of the solution:
in 1to query, we updated the field validade
of the current user with the date and time added to 5 minutes, using the functions NOW() and ADDTIME() of Mysql itself (NOW()can be replaced by the internal variable CURRENT_TIMESTAMP if you prefer).
in 2to query, we compare the field validade
with the current moment. If these 5 minutes have not yet passed, the comparison will be true, and the user in question included in the results.
Users have to be authenticated to appear, right?
– pc_oc
yes , on the site will only view the content of the logged in users
– Arsom Nolasco
then creates a table with the user id and status. Each time the user logs in, the state changes. To see that you are logged in, just make a query to this table
– pc_oc
Yes, I know how to do that, but what is the problem? theoretically it was to list only those that the timestamp and less than 5 minutes am I right? I want to know the pq is not listing OBS: the update is working perfect , records in the field the team, what is picking and that at the time of displaying it is displaying everything as if it had not the condition of WHERE
– Arsom Nolasco
Check this line, the skins $result = mysql_query("SELECT * FROM new_users WHERE timestamp < '$timeout'");
– pc_oc
It really wasn’t that either
– Arsom Nolasco