//TODAY'S DATE
$today = time();
//FETCHES DATE AND TIME FOR THE EVENT FROM DATABASE
$sql = "SELECT * FROM post";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$Row = (mysqli_fetch_assoc($result));
$th = $Row['endtime'];
}
echo $th
first of all put it into a variable then use your javascript to call the variable
//let get todays date here
var today = new Date();
var DD = today.getDate();
var MM = today.getMonth()+1; //January is 0!
var YYYY = today.getFullYear();
//let get the Difference in Sec btw the two dates
var _DateFromDBProgEndDate = '<?php echo $th; ?>';
var ProgEndTime = new Date(_DateFromDBProgEndDate);
var TodayTime = new Date();
var differenceTravel = ProgEndTime.getTime()- TodayTime.getTime() ;
var seconds = Math.floor((differenceTravel)/(1000));
////////////////////////////////
var SecDiffFromToday = seconds;
var seconds = SecDiffFromToday;
function timer() {
var days = Math.floor(seconds/24/60/60);
var hoursLeft = Math.floor((seconds) - (days*86400));
var hours = Math.floor(hoursLeft/3600);
var minutesLeft = Math.floor((hoursLeft) - (hours*3600));
var minutes = Math.floor(minutesLeft/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('countdown').innerHTML = days + ":" + hours + ":" + minutes + ":" + remainingSeconds;
if (seconds == 0) {
clearInterval(countdownTimer);
document.getElementById('countdown').innerHTML = "Completed";
} else {
seconds--;
}
}
var countdownTimer = setInterval('timer()', 1000);
</script>
the javascript call in the variable with '<?php echo $th; ?>'; then the javascript does the count down with out refreshing the page
如果你希望有人为你写这个,你将不得不提供更详细的要求和建立一个支付方案。如果您尝试过某种方法时遇到问题,那么您应该发布相关问题的代码。 – Pointy 2011-04-11 14:57:10
是的,这将是一个更好的方法,我有点写这个,因为我正在离开工作,在经过多次试验和错误后,我设法修改这个http://andrewu.co.uk/clj/countdown/pro /做我需要的东西 – Scott 2011-04-12 10:50:29
你能以一种能够帮助他人的方式回答你自己的问题吗?如果你这样做,你可以选择你的正确答案。这看起来很奇怪,但它是处理这种情况的首选方式。 – Will 2011-04-12 19:02:24