Score user who accessed the site 4 days in a row

Asked

Viewed 58 times

-3

Every time the user enters the system (logs in), their data is saved in the database, including a Timestamp column.

I’m at a loss to solve the following problem:

if (usuario entrou 4 dias SEGUIDOS) 
{echo " Ganha 10";}
else { echo " Não ganha nada "; }

I honestly couldn’t think of a few code writing, all that comes to mind are dozens of lines (gambiarras).

Is there a simple way to solve ?

Grateful !

  • 1

    Post your code so we can help

1 answer

0

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 !

  • I decided doing two different update, following the same logic, works well !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.