Log in

View Full Version : php countdown?



andy_DT
08-09-2007, 12:35 PM
Hey all, what i need to create is a php count down. But with the added difference of it being resetable. For example i need it to count down like a clock for say 2 weeks. Then after the 2 weeks are up, it will pause for 1 day and then start to count down 2 weeks again, ive made one in flash before but i had to specify a date which i wanted to countdown to.

I would like to know if this is possible to do this, because like i said i have done one in flash and it requires a date, i have also seen php ones that require dates.

If anyone can help that would be great.


Thanks

andy_DT
08-10-2007, 03:13 PM
i will take a guess this isnt possible then.

djr33
08-10-2007, 04:40 PM
<?
//ignore this line &#37;


$time = /*time*/; //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;
?>

Something like that.

This counter will not be live, so if you need it to change on the page, you'll need to use PHP to give javascript a value (just echo the PHP results into the source in the middle of the javascript to set a variable), then you could do a continuous countdown that way.

andy_DT
08-10-2007, 06:45 PM
cheers dude ill give it a shot ;)



EDIT * can you give a little more help?? sorry im newish (i know some but.. not much ).. to php. Or point me to a nice tut :) ta

like the echo how do i echo it to show the day hour and mintue??


<?
//ignore this line &#37;


$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>";

?>

thats what i have you see and i get this www.dirttag.com/Login/counter.php

djr33
08-10-2007, 10:02 PM
Er.... my math is off.

You can probably also just use date() anyway.
See here:
http://www.php.net/manual/en/function.date.php

seconds: date('s');
min: date('i');
hr: date('H');
days: date('j');