After having a suggestion from the previous question.
I am now having my visitors count using the database. On writing the script, I had a doubt so took helped of SO.
Suppose my database has a table named as Total
and the value is 5
.
Two different visitors visit the site at the same time, my script
$sqltc = "UPDATE visits SET Total='$ttl' WHERE Sr=1";
mysqli_query($link, $sqltc);
will try to update the database.
Now my doubt is what will be the new value in the table?
5
OR 6
OR 7
OR anything else
?
I know its a rare case, but the site in which the script will be used is quiz site and there will be bulk of visitors visiting simultaneously.
Full code of the script:
$sql = "SELECT * FROM visits WHERE Sr = '1'";
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result);
$date = $row['Date'];
$ttcounter = $row['Total'];
$ttcounter++;
$ttl = $ttcounter;
$sqltc = "UPDATE visits SET Total='$ttl' WHERE Sr=1";
mysqli_query($link, $sqltc);