Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
116
rated 0 times [  121] [ 5]  / answers: 1 / hits: 39715  / 13 Years ago, fri, august 19, 2011, 12:00:00

After spending the last 45 minutes looking around for a solution, I can't seem to find an easy solution to creating a countdown timer using PHP and jQuery. Most already built scripts I've found are based purely on jQuery which require a ton of code, and more parameters then they should, plus, adaptability is pretty hard.



Here's my situation;



PHP:



$countdown = date(h:i:s); // This isn't my actual $countdown variable, just a placeholder



jQuery:



$(document).ready(function name() {
$(#this).load( function() {
setTimeout(name(), 1000)
}
}
});


HTML:



<div id=this><?php echo($countdown); ?></div>



My idea is that, every second, #this is reloaded, giving a new value to it's contents, and as $countdown isn't a static variable, a new value will be loaded each time. This removes the need to deal with sessions (as a basic javascript countdown timer would reset on pageload, etc).



I would've though this would have worked, until I realized that the event binder .load() doesn't reload #this (I know silly me), so I guess what I'm wondering is - is there an event binder I can use to make this work or is there a way to get the functionality I'm looking for, without using a jQuery plugin (which doesn't match exactly what I want anyway)?


More From » php

 Answers
503

You should use Keith Wood's countdown timer: http://keith-wood.name/countdown.html



It is extremely easy to use.



All you have to do is



$('#timer').countdown({
until: '<?php echo date(h:i:s); ?>' // change this, obviously
});


Here's the fiddle: http://jsfiddle.net/tqyj4/289/


[#90540] Wednesday, August 17, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leiaf

Total Points: 10
Total Questions: 101
Total Answers: 84

Location: Guam
Member since Tue, Nov 29, 2022
2 Years ago
;