montevi Posted August 28, 2006 Share Posted August 28, 2006 Hey all! I am new here so be kind. ;)I have a little counterscript. I would like to grab the printout presented in years, months, days, hours, minutes, seconds and make them into Unis of 60 minutes and have those count down together with the countdown in time.Say I have 4 days 5 hours and 2 minutes on the countdown.then I'd like to add a function that divided tose into hours and present that. How would I go on about doing this? The script uses mktime. <?php// parameters: (year, month, day, hour, minute, seconds)countdown(2006,8,31,14,0,0);function countdown($year, $month, $day, $hour, $minute){ $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1); $today = time(); $difference = $the_countdown_date - $today; if ($difference < 0) $difference = 0; $days_left = floor($difference/60/60/24); $hours_left = floor(($difference - $days_left*60*60*24)/60/60); $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60); echo "Today's date ".date("F j, Y, g:i a")."<br/>"; echo "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>"; echo "Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";}?>Do I need to add another function or could I just add another echo row.. and how would that be written? I am a newbie just trying to figure this out.I would need to grab the hours and count up and being able to define what hour it should start counting from and print that. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2006 Share Posted August 28, 2006 php scripts execute ONCE on the server and deliver output to the browser, so php isn't really suitable for this.I think you'll find many, many, examples of javascript countdown timers that will work for you. Quote Link to comment Share on other sites More sharing options...
montevi Posted August 28, 2006 Author Share Posted August 28, 2006 No this is exactly what I want. Bt presented in hours sinstead of days etc. :)I only want it to tick once you load the page. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 just multiply the number of days by 24 and add it to the hours. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2006 Share Posted August 28, 2006 Then delete the line where days_left is calculated, and delete the reference to days_left in the output. Quote Link to comment Share on other sites More sharing options...
montevi Posted August 28, 2006 Author Share Posted August 28, 2006 This is what I did. Thanks for getting me into thinking. I am stupid. I just took the days divided those in 24 and added the hours. And printed days as hours (Units). $units_left = floor($difference/60/60/24*24); $hours_left = floor(($difference - $units_left*60*60*24/24)/60/60); $minutes_left = floor(($difference - $units_left*60*60*24/24 - $hours_left*60*60)/60); echo "Today's date ".date("F j, Y, g:i a")."<br/>"; echo "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>"; echo "Countdown ".$units_left." Units ".$minutes_left." minutes left"; To be able to print both info on Days/Hours/Minutes and Units/Minutes I renamed both Hours and Days. But to you this is kidsplay, I am happy it got solved though!Thank you again. :) Quote Link to comment 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.