•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 427,935 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,936 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 433 | Replies: 5
![]() |
•
•
Join Date: Jul 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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:
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>•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
•
•
var seconds= <?=$aegs?>;
ie.,
var seconds= "<?=$aegs?>";
Do the same with the rest of javascript variables. Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
You have the javascript within the PHP loop.
You need to take it out so that it loads only once.
You need to take it out so that it loads only once.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
A solution has already been suggested to you. Move the dynamically generated Javascript out of the looping construct. To understand more, take a look at the generated source code by navigating to 'View' -> 'View Source' in Firefox.
I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: dynamic form-field generation with javascript
- Next Thread: Javascript Counter to zero survive postbacks



Linear Mode