User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jul 2008
Posts: 3
Reputation: Keased is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Keased Keased is offline Offline
Newbie Poster

Can anyone help me?

  #1  
Jul 18th, 2008
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>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Can anyone help me?

  #2  
Jul 18th, 2008
var seconds= <?=$aegs?>;
Try with double quotes around.
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*
Reply With Quote  
Join Date: Sep 2005
Posts: 689
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 6
Solved Threads: 41
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: Can anyone help me?

  #3  
Jul 18th, 2008
You have the javascript within the PHP loop.

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!
Reply With Quote  
Join Date: Jul 2008
Posts: 3
Reputation: Keased is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Keased Keased is offline Offline
Newbie Poster

Re: Can anyone help me?

  #4  
Jul 18th, 2008
Hm upper quotes didn't work,
i'm not getting the second idea pretty well,
how am i supposed to take the script out and doesent it only load 1 counter then?
Reply With Quote  
Join Date: Jul 2008
Posts: 3
Reputation: Keased is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Keased Keased is offline Offline
Newbie Poster

Re: Can anyone help me?

  #5  
Jul 19th, 2008
No one?
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,863
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Can anyone help me?

  #6  
Jul 19th, 2008
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:23 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC