javascript - Want to implement countdown timer in php -
i have use following code countdown timer
in php page.it's works fine, problem not take time database. if insert 20 (datatype time) table , run php code takes 13hr , time changes depending on system time. have failed understand logic of takes.
please help...! thanks.
$t1=mysql_query("select * mst_test test_id='$tid'"); $t2=mysql_fetch_row($t1); $_session['targetdate']=$t2[4]; $targetdate = $_session['targetdate']; } else { // no session variable, red mysql $result=mysql_query("select * mst_test 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 test id, based on id fetch time database , gave time datatype time in database.
this 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" } }
Comments
Post a Comment