title: Multiple Countdown using PHP and Javascript
body: <p>I am currently stuck on a problem and not sure how to solve it. I am new to php and javascript coding so do please correct me if there is an easier way to do this.</p>
  
  <p>My problem is that I am trying to get a countdown timer working for multiple data in mysql database. I have already made a successful countdown time function that only works with one data using the if statement in php, but when I try to do it with multiple data using the while statement in php it doesn't work.here is my php code</p>
  
  <pre><code>//TODAY'S DATE
  $today = time();
  
  //FETCHES DATE AND TIME FOR THE EVENT FROM DATABASE
  $sql = "SELECT * FROM post";
  $result = mysqli_query($conn, $sql);
  
  while ($row = mysqli_fetch_assoc($result)) {
      $title = $row['title'];
      $cname = $row['cname'];
      $team = $row['team'];
      $description = $row['description'];
      $endtime = $row['endtime'];
  
      echo "&lt;tr&gt;";
      echo "&lt;td width='16%'&gt;&lt;strong&gt;Title:&lt;/strong&gt;&lt;/td&gt;";
      echo "&lt;td width='16%'&gt;$title&lt;/td&gt;";
      echo "&lt;/tr&gt;&lt;tr&gt;";
      echo "&lt;td width='16%'&gt;&lt;strong&gt;Client name:&lt;/strong&gt;&lt;/td&gt;";
      echo "&lt;td width='16%'&gt;$cname&lt;/td&gt;";
      echo "&lt;/tr&gt;&lt;tr&gt;";
      echo "&lt;td width='16%'&gt;&lt;strong&gt;Team:&lt;/strong&gt;&lt;/td&gt;";
      echo "&lt;td width='16%'&gt;$team&lt;/td&gt;";
      echo "&lt;/tr&gt;&lt;tr&gt;";
      echo "&lt;td width='16%'&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/td&gt;";
      echo "&lt;td width='16%'&gt;$description&lt;/td&gt;";
      echo "&lt;/tr&gt;&lt;tr&gt;";
      echo "&lt;td width='16%'&gt;&lt;strong&gt;End time:&lt;/strong&gt;&lt;/td&gt;";
      echo "&lt;td width='16%'&gt;$endtime&lt;/td&gt;";
      echo "&lt;/tr&gt;&lt;tr&gt;";
      echo"&lt;/BR&gt;";
      echo"&lt;/BR&gt;";
  }
  
  $conn-&gt;close();
  </code></pre>
  
  <p>below is my javascript that suppose to run the count down </p>
  
  <pre><code>&lt;script language="JavaScript"&gt; 
  var today = new Date();
  var DD = today.getDate();
  var MM = today.getMonth()+1; //January is 0!
  var YYYY = today.getFullYear();
  //let get the Difference in Sec btw the two dates
  var _DateFromDBProgEndDate = '&lt;?php echo $endtime; ?&gt;';
  var ProgEndTime = new Date(_DateFromDBProgEndDate);
  var TodayTime = new Date();
  
  var differenceTravel = ProgEndTime.getTime()- TodayTime.getTime() ;
  var seconds = Math.floor((differenceTravel) / (1000));
  ////////////////////////////////
  var SecDiffFromToday = seconds;
  var seconds = SecDiffFromToday;
  
  function pad(n) {
     // utility function to pad a number to 2 digits:
     return ('0' + n).substr(-2); 
  }
  
  function timer() {
      var todaySeconds = Math.floor(new Date().getTime() / 1000);
      // collect the html first in an array
      var html = [];
      // keep track whether there are still counters not yet zero:
      var allDone = true;
      // go through the list of dates:
      endDatesInSeconds.forEach(function (endDateSeconds) {
          var totalSeconds = endDateSeconds - todaySeconds;
          var days        = Math.floor(totalSeconds/24/60/60);
          var seconds     = Math.floor(totalSeconds - days*86400);
          var hours       = Math.floor(seconds/3600);
          seconds         = Math.floor(seconds - hours*3600);
          var minutes     = Math.floor(seconds/60);
          seconds         = seconds % 60;
          // add a part of html
          html.push(
              totalSeconds &lt;= 0 
                 ? 'project time Completed'
                 : days + ":" + pad(hours) + ":" + pad(minutes) + ":" + pad(seconds));
          // when at least one counter is not complete, we are not done:
          allDone = allDone &amp;&amp; totalSeconds &lt;= 0;
      });
      // now put the html in the document:
      document.getElementById('countdown').innerHTML = html.join('&lt;br/&gt;');
      if (allDone) {
          clearInterval(countdownTimer);
      }
  }
  
  var countdownTimer = setInterval('timer()', 1000);
  &lt;/script&gt; 
  </code></pre>
  
  <p>the javascript run the countdown by getting it value from the php  (<code>var _DateFromDBProgEndDate = '&lt;?php echo $endtime; ?&gt;';</code>)</p>