I would like to set a countdown for each row in my table but my problem is that the only first countdown is displayed in the table and currently I set the end in the code but I want to add the date in my database then trigger the countdown when it's setted.
there is the code in the php file:
<table>
<tr>
<td><?php echo $donnees['type'];?></td>
<td><?php echo $donnees['number'];?></td>
<td><?php echo $donnees['weight'];?></td>
//this date is the date of birth
<td><?php echo $donnees['date'];?></td>
<td><p id="ctd"></p></td>
</tr>
</table>
the script to set the countdown :
var countDownDate = new Date("Sep 20, 2018 15:00:00").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
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);
document.getElementById("ctd").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
if (distance < 0) {
clearInterval(x);
document.getElementById("ctd").innerHTML = "EXPIRED";
}
}, 1000);