andyjoneski Posted August 11, 2007 Share Posted August 11, 2007 What i have been trying to do is make a count down timer, which counts down two weeks and once its done it waits for a day and then resets it self to count down two weeks again. I have tried. the code below but it doesnt seem to come out right. Please can you help <? //ignore this line % $time = time()+(2*7*24*60*60); //use this to set the end date //ex: you could use time()+(2*7*24*60*60) //or specify using mktime(), etc $rem = $time-time(); $sec = $time%(60); $min = $time%(60*60); $hr = $time%(60*60*24); $days = round($time/(60*60*24)); //do whatever now, like echo; { echo "<table>"; echo "<tr>"; echo "<td>" . $sec. "</td>"; echo "<td>" . $min. "</td>"; echo "<td>" . $hr. "</td>"; echo "<td>" . $days. "</td>"; echo "</tr>"; } echo "</table>"; ?> www.dirttag.com/Login/counter.php Quote Link to comment https://forums.phpfreaks.com/topic/64414-count-down-help/ Share on other sites More sharing options...
hitman6003 Posted August 11, 2007 Share Posted August 11, 2007 <?php //select our start date/time...this is a constant to base our //future dates off of. $start_date = mktime(12, 0, 0, 8, 11, 2007); //now... $current_date = time(); //find the difference in seconds $difference = $current_date - $start_date; //find the difference in days $days_difference = floor($difference / 86400); if ($days_difference % 14 == 0) { echo "Today is a day that is 2 weeks from the last day"; } else if ($days_difference % 14 >= 1) { echo "There are " . (14 - ($days_difference % 14)) . " days until the next same day"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64414-count-down-help/#findComment-321136 Share on other sites More sharing options...
andyjoneski Posted August 11, 2007 Author Share Posted August 11, 2007 thats a great bit of code is there anyway to make it live so for example ... http://www.dirttag.com/Login/countdown.swf i made that in flash but it isnt resetable after 2 weeks all it does is count down to a selected date Quote Link to comment https://forums.phpfreaks.com/topic/64414-count-down-help/#findComment-321140 Share on other sites More sharing options...
Wuhtzu Posted August 11, 2007 Share Posted August 11, 2007 You need java script to do that... do a search on google for "java script countdown" Quote Link to comment https://forums.phpfreaks.com/topic/64414-count-down-help/#findComment-321159 Share on other sites More sharing options...
andyjoneski Posted August 11, 2007 Author Share Posted August 11, 2007 cheers dude i found one would you have any idea how to make it like i said ? or would i need to ask else where?? Quote Link to comment https://forums.phpfreaks.com/topic/64414-count-down-help/#findComment-321166 Share on other sites More sharing options...
Wuhtzu Posted August 12, 2007 Share Posted August 12, 2007 You combine the PHP code and the javascript code to obtain the result you want. Javascript is "executed" after your page has been processed by PHP so you can use PHP to create javascript code... Here is an example: <?php $name = "Your Name"; $age = "60"; ?> <script type="text/javascript"> alert("Hello <?php echo $name; ?>, you are <?php echo $age; ?> years old."); </script> So basically you use your PHP code to calculate how many days are left of the countdown and pass that number on to the javascript. So each time your page, which contains the count down, is requested PHP will calculate how much time is left but instead of printing it to the browser it passes the value on to a javascript which then counts down until the user leaves the page Quote Link to comment https://forums.phpfreaks.com/topic/64414-count-down-help/#findComment-321572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.