3
I have the following table which is built from a database entity.
HTML:
<table class="table table-hover" id="produtostab">
<thead>
<tr>
<th>Descrição</th>
<th>Quantidade</th>
<th>Selecionar</th>
</tr>
</thead>
<tbody id="myTable">
<?php
$conn = new mysqli('localhost', 'root', '', 'exemplo') or die ('Falha ao conectar-se com DB');
mysqli_query($conn, "SET NAMES 'UTF8'") or die("ERROR: ". mysqli_error($con));
$result = $conn->query("select idProduto, Descricao from produto");
while ($row = $result->fetch_assoc()) {
unset($idProduto, $Descricao);
$idProduto = $row['idProduto'];
$Descricao = $row['Descricao'];
echo '<tr>';
echo '<td>'.$Descricao.'</td>';
echo '<td contenteditable="true"></td>';
echo '<td><input type="checkbox"></td>';
echo '</tr>';
}
?>
</tbody>
</table>
In each Row (row) of the table, there is a checkbox. I need that, after pressing a push button, the contents of all Rows that are checked (from the checkbox) are stored in a PHP array to be consulted later. How could I do that? I do not know if it is possible, if it is not, there is another way to get the values of these verified Rows?
Thank you, that’s exactly what I need. I just needed to remove the
first-of-type
, because otherwise he would not capture the value of the second<td>
, where in your example is Value 1, Value 2, etc. It worked perfectly.– valkyrieQNTUM
Yes, you can use
td:eq(0)
andtd:eq(1)
.– Marta
I also imagine that another approach was needed than simply throwing the values on another element, like concatenating the data into a string, creating a JSON... And AJAX, of course, to pass data from client to server.
– Bruno Augusto
Instead of passing the values to a
<div>
, it is possible to pass them to thevalue
field<input>
?– valkyrieQNTUM
Just put a
<input id="campo" name="campo">
and$(".campo").val(total)
– Marta