Jump to content

count down help


andyjoneski

Recommended Posts

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

 

 

Link to comment
Share on other sites

<?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";
} 
?>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.