Hello guys.
I had a few problems with this script, I fixed all the errors and such, but it isn't functioning the way I want it to :/
the Idea is this:
I was going to grab the current time using time();
and place it into the database.
Then I would set another value in the structure called check, to 1.
The database while the value is set on 1 will keep checking every time a user refreshes.
It would get the time from the database that was set, and the current time again. It would take away the stored time from the current time and if that value equals less then ten, it would keep running the script and won't change the check. But if it was over ten, it would do a random function (What ever the user wanted, right now it just an echo for a test) and delete both the current timestamp in the database, and set the check to 0.
If the value was 0, it would set the new timestamp in the database, eg the current time, and set the value to 1 so it will keep running again.
Is this possible?
If it was, I tried.
Here is my code:
<?php
$db = mysql_pconnect("localhost","root","");
mysql_select_db("test",$db);
$time = time();
$result = mysql_query("SELECT * FROM timer");
while($row = mysql_fetch_array($result))
{
$timestamp = $row['timestamp'];
$check = $row['check'];
if ($check=="0") {
mysql_query("UPDATE timer SET check = '1' WHERE id = '1'");
mysql_query("UPDATE timer SET timestamp = '$time' WHERE id = '1'");
}
elseif ($check=="1") {
$timenow = time();
$timecheck = $timenow - $timestamp;
echo $timenow;
echo $timecheck;
if ($timecheck >= "10") {
echo "bigger then 10, do what ever at the end of the countdown here";
mysql_query("UPDATE timer SET check = '0' WHERE id = '1'");
mysql_query("UPDATE timer SET timestamp = '' WHERE id = '1'");
}
}
}
?>
Yeah.
The problem, so fare it doesn't update the database with the new timestamp, and it just echo's the current timestamp
I haft to manually change the check from 1 to 0 to get the 2 things to change.
So that means, so fare none of the updates work from what I can tell.
Anything else you guys can see?