HI i would be more than thankful if anybody can tell me why this don't work,
the problem is that the JS counter won't work when there are more then 1 entrys in mysql.
With one entry the script runs fine.
Heres the code:
<table>
<?
//Connect to mysql server
$link = mysql_connect("database connect works","...","...");
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db("niisama");
if(!$db) {
die("Unable to select database");
}
$asjad = mysql_query("SELECT aegs,aegm,aegh,aegp,aegk,aega FROM tehingud;");
if (mysql_num_rows($asjad) == 0) break;
while ($asi = mysql_fetch_array($asjad))
{?>
<table width="200" border="0">
<tr>
<tr>
<th scope="row">Aega Jäänud</th>
<td>
<form name="counter"><input type="text" size="8"
name="d2"></form> <script>
<!--
//
<?
$aegs=60-date("s" ,time());
$aegm=$asi[aegm]-date("i" ,time())-1;
$pkuus=$asi[aegp]-date("d" ,time());
if($pkuus<0)
{
$pkuus=date("t" ,time())-date("d" ,time())+$asi[aegp];
}
$aegh=$pkuus*24+$asi[aegh]-date("H" ,time());
if($aegm<0)
{
$aegh-=1;
$aegm=60+$aegm;
}
$aegp=$asi[aegm];
$aegk=$asi[aegm];
$aega=$asi[aegm];
?>
var milisec=0;
var seconds= <?=$aegs?>;
var minutes= <?=$aegm?>;
var hours= <?=$aegh?>;
document.counter.d2.value='30'
function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
seconds=59
minutes-=1
}
if (minutes<=-1){
minutes=59
hours-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1;
document.counter.d2.value=hours+":"+minutes+":"+seconds;
setTimeout("display()",100)
}
display()
-->
</script> </td>
</td>
</tr>
</table>
<br />
<?
}
?>
</table>