I am making a text-based browsergame that is based on time events. I am now creating a script in php / javascript wich is a countdown clock that counts down from 3 minutes to 0.
It is important that this clock is the same for every visitor and doesn't stop counting when the page is refreshed. If the clock reaches 0 then it must start at 3 min againg.
I have written a script but it doens't work. It counts down till 0 but doens't reset to 3 minutes then but is just keeps ticking down under 0.
Can someone help me with this problem ? Maybe it's possible with a cronjob ?
My script
----------------------------------
<?php
include('contactdb.php');
?>
<HTML>
<HEAD>
<BODY>
<form name=myForm>
<input type="text" name="clock" size="6"></form>
<SCRIPT LANGUAGE="JavaScript"><!--
function runClock(){
theTime = window.setTimeout("runClock()", 1000);
var nu = new Date();
var tick = new Date();
<?php
$sql = "SELECT Minuten FROM `tickgegevens`";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($res) or die(mysql_error());
?>
tick.setMinutes(<?php echo $row['Minuten']; ?>);
var verschil = new Date();
verschil.setTime(parseInt(tick.getTime()-nu.getTime()));
tmin = (Math.round(verschil.getTime()/1000/60)-1);
tsec = (60-nu.getSeconds());
if(tmin <= 9){tmin="0"+tmin}
if(tsec <= 9){tsec="0"+tsec}
if (tsec == 01) {
if (tmin == 00) {
<?php
$tabelMin=date("i")+1;
$tabelSec=date("s");
$sql = "UPDATE `tickgegevens` SET Minuten='$tabelMin', Seconden='$tabelSec'";
$res = mysql_query($sql) or die(mysql_error());
?>
} }
document.myForm.clock.value=""+tmin+":"+tsec+"";
}
runClock();
//--></script>
</BODY>
</HEAD>
</HTML>
--------------------------------------
It is important that this clock is the same for every visitor and doesn't stop counting when the page is refreshed. If the clock reaches 0 then it must start at 3 min againg.
I have written a script but it doens't work. It counts down till 0 but doens't reset to 3 minutes then but is just keeps ticking down under 0.
Can someone help me with this problem ? Maybe it's possible with a cronjob ?
My script
----------------------------------
<?php
include('contactdb.php');
?>
<HTML>
<HEAD>
<BODY>
<form name=myForm>
<input type="text" name="clock" size="6"></form>
<SCRIPT LANGUAGE="JavaScript"><!--
function runClock(){
theTime = window.setTimeout("runClock()", 1000);
var nu = new Date();
var tick = new Date();
<?php
$sql = "SELECT Minuten FROM `tickgegevens`";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($res) or die(mysql_error());
?>
tick.setMinutes(<?php echo $row['Minuten']; ?>);
var verschil = new Date();
verschil.setTime(parseInt(tick.getTime()-nu.getTime()));
tmin = (Math.round(verschil.getTime()/1000/60)-1);
tsec = (60-nu.getSeconds());
if(tmin <= 9){tmin="0"+tmin}
if(tsec <= 9){tsec="0"+tsec}
if (tsec == 01) {
if (tmin == 00) {
<?php
$tabelMin=date("i")+1;
$tabelSec=date("s");
$sql = "UPDATE `tickgegevens` SET Minuten='$tabelMin', Seconden='$tabelSec'";
$res = mysql_query($sql) or die(mysql_error());
?>
} }
document.myForm.clock.value=""+tmin+":"+tsec+"";
}
runClock();
//--></script>
</BODY>
</HEAD>
</HTML>
--------------------------------------