4

Note * I want some one to fix it and tell me how they did it not tips on how to do it or coments about php nd java mixed in it *

I have a countdown script that is working, but when it hits the target date the timer keeps on going to a negative time. I want it to stop on that target date and just display a finishing message. It's live on my site. I just need help editing the countdown script.

I want to keep the same layout. I need some help adding the finishing message and stopping it from going into the negative date, or just make it not display the 0days, 0 hours, 0mins, 0sec until the site's officially released. When that finally happens, I want it to display a message.

countdown script

<?php date_default_timezone_set('EST'); ?>
<?php
// Define your target date here
    $targetYear  = 2011;
    $targetMonth = 9;
    $targetDay   = 1;
    $targetHour  = 20;
    $targetMinute= 00;
    $targetSecond= 00;
// End target date definition

// Define date format
$dateFormat = "Y-m-d H:i:s";

$targetDate = mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear);
$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));

$targetDateDisplay = date($dateFormat,$targetDate);
$actualDateDisplay = date($dateFormat,$actualDate);

?>
<script type="text/javascript">
  var days = <?php echo $remainingDay; ?>  
  var hours = <?php echo $remainingHour; ?>  
  var minutes = <?php echo $remainingMinutes; ?>  
  var seconds = <?php echo $remainingSeconds; ?>  
</script>
<body onLoad="setCountDown();">
<center><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes and $remainingSeconds seconds";?> untill official release</center>

how its added on the site

<script type="text/javascript">
$(function() {
    /* Union War */
    $("#Countdown2").load("http://imperialism.zxq.net/includes/process/uwcountdown.php");

    setInterval(function(){
        $("#Countdown2").load("http://imperialism.zxq.net/includes/process/uwcountdown.php");
    }, 1000);
});
</script>

<div id="uwCD" class="uwCD">
    <div id="Countdown2"></div>
</div>
4
  • 1
    Ok, so where's the script (ie: the .js file) you are using? Is it being included somewhere? Commented Sep 2, 2011 at 1:27
  • (1) the problem is in JavaScript (setCountDown function I would assume), but it's not in example that you provided. The solution is (probably) where you calculating remaining value, just add a condition which checks how much time is remaining. (2) just as a side-note, not quite sure why do you need to mix php and javascript in this script. I think it will be nicer just to have it all in javascript. Commented Sep 2, 2011 at 1:54
  • See stackoverflow.com/questions/6420455/countdown-timer-phpmysqljs/… Commented Sep 2, 2011 at 2:27
  • @sanmai sorry but thats not what im doing its set to a target date and its not running from mysql Commented Sep 2, 2011 at 2:33

4 Answers 4

2

I recommend this jQuery countdown plugin; just pass the PHP value to the jQuery plugin call.

Sign up to request clarification or add additional context in comments.

Comments

2
if($targetDate != $actualDate && $targetDate > $actualDate) {
echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes and $remainingSeconds seconds";
} else {
echo "0 days, 0 hours, 0 minutes and 0 seconds";
}

Comments

2

try using this http://www.timeanddate.com/counters/customcount.html everything is done for you and its worked fine and if anything you can just edit the look of the skin to fit your website

Comments

0
if($targetDate != $actualDate && $targetDate > $actualDate) { 
echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes and $remainingSeconds seconds"; 
} else { 
echo "0 days, 0 hours, 0 minutes and 0 seconds"; 
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.