Here’s what I did:
When the user enters I perform a query:
$sql = "SELECT * FROM ed_sv_dadosnavegador where idaluno = '$id' and data = '$data_anterior' ";
I created a conditional, if the $sql above returns something greater than 0, it means that there is a date in the database that corresponds to the previous day then add +1 in the column "account_access"
$result = $conn->query($sql);
if ($result ->num_rows > 0) {
$set = 'conta_acesso = conta_acesso + 1, data = 0 '; }
If it’s fake, I zero the count
else { $set = 'conta_acesso = 0 '; };
This code below is the running update
$sqlup = "UPDATE `ed_sv_dadosnavegador` SET $set WHERE `idaluno` = '$id' ORDER BY conta_aceso, id LIMIT 1 ";
if ($conn->query($sqlup) === TRUE) {
$mensagemalerta = "Tudo certo";}
As messy as all this sounds, it’s working. The ONLY problem I’ve come across now is that by putting LIMIT 1 on $sqlup, in case it’s true, I can’t clear the date of the tables and if I don’t, when the user updates the page starts a new count.
I’m a beginner, I’m sorry for the mess, but I’ve been up all night on this one, so if anyone can help, better, every suggestion is welcome !
Post your code so we can help
– Albertt Santos