I have a db table with several fields and i want to make a countdown with the integer value of one of the fields (as minutes). How can i loop and display the countdown of each of those rows in a php table using these values and adding or subtracting time in the process if I need to?
Table.php
$sql="SELECT * FROM List where depName='Admisiones' and personStatus='Espera'";
$result=mysqli_query($con, $sql);
echo "<table border='15' cellpadding='10' cellspacing='3' bordercolor='00FF00'>
<tr>
<th>Turno</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Segundo Apellido</th>
<th>Id Studiante</th>
<th>Status</th>
<th>Multiples Motivos</th>
<th>Tiempo Categoria</th>
<th>Tiempo Estimando</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['listNum'] . "</td>";
echo "<td>" . $row['personName'] . "</td>";
echo "<td>" . $row['personLast'] . "</td>";
echo "<td>" . $row['secondLast'] . "</td>";
echo "<td>" . $row['stuId'] . "</td>";
echo "<td>" . $row['personStatus'] . "</td>";
echo "<td>" . $row['manyMotive'] . "</td>";
echo "<td>" . $row['categoryTime'] . "</td>";
echo "<td>" . $row['estimatedTime']"</td>"; //USE THE CLOCK.PHP TO MAKE A COUNTDOWN FOR EACH ESTIMATED TIME.
//And have the ability to add or substrac time if needed.
echo "</tr>";
}
echo "</table>";
Clock.php
<script>
$('.countdown').each(function(){
var minutes = $(this).data('minutes');
var count = $(this); //countdown
var id = $(this).id;
$(this).countdown({
date : Date.now() + (minutes * 60000),
refresh : 1000
});
setInterval(function(count)
var minuteValue = count.text();
$.ajax({
url : 'TEST.php', //I created to make the test..
type : 'POST',
data : {currentMin : minuteValue, id:id},
success : function(response){
console.log(response);
}
});
});
});
TEST.php
<?php
include 'Connection.php';
$minValue = mysqli_real_escape_string($con, $_POST['minuteValue']);
$ID = mysqli_real_escape_string($con, $_POST['id']);
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
$sql ="Update List SET estimatedTime='$minValue' WHERE listNum='$ID'";
mysqli_query($con,$sql);
mysqli_close($con);
?>