killah Posted March 28, 2009 Share Posted March 28, 2009 Well, i currently have a javascript code. It count's down from 10 minute's to 0. I can syncronize the count down to the database. But exactly how do i update the database per second using the javascript code? <?php $x_m = '10 '; $x_s = '59 '; ?> <script language="javascript"> var x_m = <?php echo $x_m; ?> function startClockMinutes() { if(x_m !== 0) { x_m = x_m - 1 document.frm.clock_minutes.value = x_m + ' minute(s)' setTimeout("startClockMinutes()", 58999) } if(x_m == 0) { x_m = 9 document.frm.clock_minutes.value = x_m + ' minute(s)' } } var x_s = <?php echo $x_s; ?> function startClockSeconds() { if(x_s !== 0) { x_s = x_s - 1 document.frm.clock_seconds.value = x_s + ' seconds left' setTimeout("startClockSeconds()",1000) } if(x_s == 0) { x_s = 59 document.frm.clock_seconds.value = x_s + ' seconds left' } } var times = 0 function set_times() { times = times + 1 document.frm.times.value = times + ' times' setTimeout("set_times()",1000) } </script> <body onload="startClockSeconds(); startClockMinutes(); set_times();"> <form name="frm"> <input type="text" name="clock_minutes" readonly size="9" /> <input type="text" readonly style="text-align: center;" value="&" size="1" /> <input type="text" name="clock_seconds" readonly size="12" /><br /> <input type="text" name="times" readonly size="4" /><br /> </form> You might see some wierd thing's. But it's for testing right now only. So can anyone tell me how i can update the database per second? If i can find that out, i can do the per minute one. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted March 28, 2009 Share Posted March 28, 2009 So can anyone tell me how i can update the database per second? If i can find that out, i can do the per minute one. You could do an ajax call every sec or min. Just a questions, is there a reason you are using javascript for this instead of using a cron job? Quote Link to comment Share on other sites More sharing options...
killah Posted March 28, 2009 Author Share Posted March 28, 2009 [..]Just a questions, is there a reason you are using javascript for this instead of using a cron job? Yes, i would like to let the user know when the next update is. Can you provide the ajax script which will update every second? Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted March 28, 2009 Share Posted March 28, 2009 [..]Just a questions, is there a reason you are using javascript for this instead of using a cron job? Yes, i would like to let the user know when the next update is. Can you provide the ajax script which will update every second? I could but instead lemme give you a link instead http://lmgtfy.com/?q=periodical+ajax+call Quote Link to comment 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.