EchoFool Posted August 25, 2009 Share Posted August 25, 2009 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 https://forums.phpfreaks.com/topic/171844-live-countdown-via-mysql/ Share on other sites More sharing options...
Goldeneye Posted August 25, 2009 Share Posted August 25, 2009 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 https://forums.phpfreaks.com/topic/171844-live-countdown-via-mysql/#findComment-906158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.