Twist3d Posted January 7, 2011 Share Posted January 7, 2011 Hello. Well I am really annoyed at myself at the moment. I am trying to make a timer script that is uninterrupted by a refresh of the page, so this to me would be a Mysql database thing to check My idea was simple, at least until I forgot it. But, 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? It is getting a bit annoying, getting a few errors, again like most of the time its little ones that I can't seem to put my finger on. Hey, we have all started somewhere :/ This is my code so fare: <?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") { $query = "UPDATE timer SET check = '1' WHERE id = '1'"; $query .= "UPDATE timer SET timestamp = '$time' WHERE id = '1'"; multi_query($query); } elseif ($check=="1") { $timenow = time(); $timecheck = $timenow - $timestamp; if ($timecheck >= "10") { echo "bigger then 10, do what ever at the end of the countdown here"; $query2 = "UPDATE timer SET check = '0' WHERE id = '1'"; $query2 .= "UPDATE timer SET timestamp = '' WHERE id = '1'"; multi_query($query2); } } ?> Now even looking at this code confuses me, and I wrote it. I tested it, I expected an error and got one. Quote Parse error: syntax error, unexpected T_ELSEIF in D:\xampp\htdocs\tests\timer.php on line 17 As you have probably already stated, I am a very small form of BASIC at PHP, would anyone like to push me in the right direction as to how to get this working? Quote Link to comment https://forums.phpfreaks.com/topic/223663-confused-timer-script/ Share on other sites More sharing options...
Twist3d Posted January 7, 2011 Author Share Posted January 7, 2011 Ok, I've fixed the errors. Now, all it is doing is this: Quote 12943942051294394205bigger then 10, do what ever at the end of the countdown here This is the 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'"); } } } ?> Why is it just echoing the current time twice, and doing what it should do if it those two where minused and if the answer was bigger then 10? Quote Link to comment https://forums.phpfreaks.com/topic/223663-confused-timer-script/#findComment-1156157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.