Reputation: 237
I have a DATETIME date in a mysql field, and i'd like the simplest timer displayed on my PHP page counting down to that. The timer will never be over a few minutes.
I'm guessing some kind of javascript php hybrid is needed?
Eg "40 secs left"
Note: I know nothing about javascript, but half decent at PHP.
Upvotes: 0
Views: 3587
Reputation: 9825
Take a look at Keith Woord's jQuery Countdown plugin. It is very easy to use and you can pass it your DATETIME on page load via PHP echo / print.
I hope this helps!
EDIT:
To implement this solution you could do the following:
<head>
...
<!-- Include jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
// Activate Countdown //
$('timerDiv').countdown({
until: new Date(<?= $date ?>), // Date need to be in "YYYY, Start - End, M" Format like this: "2012, 8 - 1, 8"
format: 'HMS' // H = Hours, M = Minutes, S = Seconds. Remove letter to omit it
});
</script>
...
</head>
<body>
<div id="timerDiv"></div>
</body>
Upvotes: 3
Reputation:
you can use jQuery Countdown for that, so you just need to provide a date in correct format described there
Upvotes: 0