Jump to content

Live countdown via MYSQL?


EchoFool

Recommended Posts

Hey,

 

Quick question, i was wondering if there is any known examples of JS working with MYSQL which can compare the value loaded from a query and counts down in 30 seconds from that point, and then when it reaches 0 it activates a script?

 

For example say i have a time stamp y-m-d hh:mm:ss

 

And then have it compare that to "NOW"  to make a count down from 30 seconds. Aka when 30 seconds pass, JS then will load a script from a certain location?

 

I have been looking for an example to work off but can't find one :(

 

Hope you can help.

Link to comment
Share on other sites

Well, I can't say I know how to do that, but here's something that will get you going in the right direction:

 

<?php
function countdown($seconds){
	$rtn = '<script type="text/javascript">
    			var goal = new Date().valueOf() + ' . $seconds * 1000 . ';
    			function countDown(){
					var count;
					count = Math.ceil((goal - new Date().valueOf())/1000);
					if(count < 0) count==0;
					if(count != 0) setTimeout("countDown()", 500);
					document.getElementById("secs").innerHTML=count;
				}
				countDown();
			</script>';
	$rtn .= '<span id="secs">' . $x . '</span>';
	return $rtn;
}
?>

 

What this PHP-function does is, using embedded JavaScript, counts down from the amount of seconds (represented as $seconds) to zero.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.