I have the following problem that I have not been able to solve. I have a timer (countdown) that is generated by each row of the datatables, which come from a database. This works well, the problem is that in all the rows, it shows me the last record corresponding to the query to the database. In the attached image, you can see that.
As you can see in the time column, the record that is datetime is repeated and that is the last one of the condition generated in mysql.
The code that it generates, this sample is the following:
{
"sClass": "alignRight",
"data": "tiempo",
'render': function (data, type, row, meta) {
var tiempo = data;
var splitDate = tiempo.split(" ");
var date = splitDate[0].split("-");
var time = splitDate[1].split(":");
var dd = date[2];
var mm = date[1]-1;
var yyyy = date[0];
var hh = time[0];
var min = time[1];
var ss = time[2];
window.countDownDate = new Date(yyyy, mm, dd, hh, min, ss).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("time-"+meta.row).innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
if (distance < 0) {
clearInterval(x);
document.getElementById("time-"+meta.row).innerHTML = "EXPIRED";
}
}, 1000);
return '<p id="time-'+meta.row+'"></p>';
}
}
The time variable is the one that brings the data json from the database that is in datetime format.
Here's the mysql query:
SELECT
permisos_pedidos.tiempo
FROM permisos_pedidos
WHERE permisos_pedidos.id_cliente = '$id_cl' AND permisos_pedidos.id_pedido = permisos_pedidos.id_pedido AND etapa_abierta = 'A'
If someone, has any idea or has run into any problem like that, I would appreciate, could guide me how to solve it. If some information is missing to clarify the problem, I will upload it without problem. Of course, thank you very much everyone.