I have the following table:
I am looking for a way to count the number of times that the positive and negative numbers appear for each column, for example: Black appears 1 time in the first column, 2 times in the second and 0 in the third (black is the only color that has negative value).
The code I have so far is the following:
<table class="table table-bordered table-hover" id="miTabla">
<thead>
<tr>
<th> Nombre </th>
<th> Lunes </th>
<th> Martes </th>
<th> Miercoles </th>
<th> Jueves </th>
<th> Viernes </th>
<th> Puntaje Obtenido </th>
<th> Puntaje Acumulado </th>
<th> Puntaje Nuevo </th>
</tr>
</thead>
<!-- Número de filas según la cantidad de usuarios activos -->
<tbody>
<?php while ($row = $query1 -> fetch_array()):?>
<tr id="<?= $row['id']; ?>">
<td><?= $row["nombre"]; ?></td>
<!-- Número de columnas = 5 -->
<?php for ($i=1; $i<=5 ; $i++):?>
<td>
<select name="puntos" id="puntos" required>
<option value=""></option>
<!-- Listado de puntos por color traído de MySQL -->
<?php
while ($valor = $query2 -> fetch_array()) {
$lista.= "<option value='".$valor['puntos']."'>".$valor['color']."</option>";
}
echo $lista;
?>
</select>
</td>
<?php endfor;?>
<td>
<!-- Puntaje Obtenido (suma de puntos de toda la fila) -->
<input class="obtenido" name="obtenido" value="" readonly>
</td>
<td>
<!-- Puntaje Acumulado traído de MySQL -->
<input class="acumulado" name="acumulado" value="<?= $row["acumulado"]; ?>" readonly>
</td>
<td>
<!-- Puntaje Obtenido + Puntaje Acumulado -->
<input class="nuevo" name="nuevo" value="" readonly>
</td>
</tr>
<script>
/*Puntaje Obtenido y Puntaje Nuevo*/
$("select").change(function(){
var i=0;
$(this).closest("tr").find("select").each(function(){
if ( $(this).val() !== "" )
i += parseInt($(this).val(), 10);
j = parseInt($(this).closest("tr").find(".acumulado").val()) + parseInt(i);
});
$(this).closest("tr").find(".obtenido").val(i);
$(this).closest("tr").find(".nuevo").val(j);
});
</script>
<?php endwhile;?>
<tr>
<td>Colores Positivos</td>
<?php for ($i=1; $i<=5 ; $i++):?>
<td>
<input class="positivos" type="" name="" style="width: 80px;">
</td>
<?php endfor;?>
</tr>
<tr>
<td>Colores Negativos</td>
<?php for ($i=1; $i<=5 ; $i++):?>
<td>
<input class="negativos" type="" name="" style="width: 80px;">
</td>
<?php endfor;?>
</tr>
</tbody>
</table>
Note: The number of rows changes depending on the number of registered users in the database and the number of columns may vary.
Here is an example of how to do it: