Good night HeshKod, there was a great difficulty, I make a chat on Ajax and I have to delete those who have not been active for 5 minutes, here is the php code.
$date = strtotime("+5 minutes"); mysql_query("DELETE FROM tb_online WHERE date < $date"); $sql = mysql_query("SELECT * FROM tb_online WHERE id_session = '$id_session'"); if(mysql_num_rows($sql) > 0){ mysql_query("UPDATE tb_online SET date = '" .time() ."' WHERE id_session = '$id_session'"); }else{ if(isset($_SESSION["username"])){ $username = $_SESSION["username"]; mysql_query("INSERT INTO tb_online(id_session, username,date)VALUES('$id_session', '$username','" .time() ."');") or die(mysql_error()); }else{ mysql_query("INSERT INTO tb_online(id_session, username,date)VALUES('$id_session', 'Гость','" .time() ."');") or die(mysql_error()); } }
Here is the Ajax code:
function getOnline(){ $.post("data.php", {data:"get"}, function(text){ $("#user").html(text); setTimeout(getOnline(), 1000); }); }
For some reason, they are permanently deleted and re-inserted (they are constantly flashing), why are they removed if the code seems to be correct, it should not be deleted immediately, and if 5 minutes was not active? What is the problem?