Please check my code below and see what i might be missing. i am new to javascript i tried reading other solutions and i cant be able to find it working.
The script is working perfectly the problem is IT ONLY DISPLAY COUNT DOWN FOR THE FIRST ROW AND IGNORE THE REST OF THE ROWS.
<!-- <p id="demo<?php echo $row['id_project'];?>"></p> -->
<p id="demo"></p>
<script>
// Set the date we're counting down to
// 1. JavaScript
// var countDownDate = new Date("Sep 5, 2018 15:37:25").getTime();
// 2. PHP
var countDownDate = <?php
echo strtotime("$date $h:$m:$s" ) ?> * 1000;
var now = <?php echo time() ?> * 1000;
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
// 1. JavaScript
// var now = new Date().getTime();
// 2. PHP
now = now + 1000;
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h " +
minutes + "m " + seconds + "s ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
@vidurath: when you post code on the forums, you need to format it so it will display correctly. (I’ve edited your last post for you.)
You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.
There are two lines in countdown3.php that involve the letter “x”. both of those should get the same PHP added directly after them, so that in the end the variables will be something like “var x123 = setInterval…”
If you leave them as ‘x’, the last timer will stop when any countdown (not just its own) reaches 0.