I have use following code for countdown timer
in Php page.It's works fine, but the problem is it does not take time from database. If i insert 20 (datatype time) into table and run the Php code it takes 13hr something and this time changes depending on system time. I have failed to understand the logic of it takes.
Please anyone help...! Thanks.
$t1=mysql_query("select * from mst_test where test_id='$tid'");
$t2=mysql_fetch_row($t1);
$_SESSION['targetDate']=$t2[4];
$targetDate = $_SESSION['targetDate'];
} else {
// No session variable, red from mysql
$result=mysql_query("select * from mst_test where test_id='$tid'");
$time=mysql_fetch_row($result);
$dateFormat = "d F Y -- g:i a";
$targetDate = $time['time'];
$_SESSION['targetDate'] = $targetDate;
}
$actualDate = time();
$secondsDiff = $targetDate - $actualDate;
$remainingDay = floor($secondsDiff/60/60/24);
$remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
$actualDateDisplay = date($dateFormat,$actualDate);
$targetDateDisplay = date($dateFormat,$targetDate);
Here $tid is Test id, based on the Id it will fetch the time from database and i gave time datatype for time in database.
This is the script:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
<div id='timer'>
<script type="text/javascript">
var days = <?php echo $remainingDay; ?>
var hours = <?php echo $remainingHour; ?>
var minutes = <?php echo $remainingMinutes; ?>
var seconds = <?php echo $remainingSeconds; ?>
function setCountDown ()
{
seconds--;
if (seconds < 0){
minutes--;
seconds = 59
}
if (minutes < 0){
hours--;
minutes = 59
}
if (hours < 0){
hours = 23
}
document.getElementById("remain").innerHTML = " "+hours+" hr "+minutes+" min "+seconds+" sec";
SD=window.setTimeout( "setCountDown()", 1000 );
if (minutes == '00' && seconds == '00') {
seconds = "00"; window.clearTimeout(SD);
window.location = "review.php"
}
}