2
With this script, written summarized because you know better than me.
<?php
$query = "select from table where status='0'";
$i=0;
while (mysqli_fetch_array)
echo '<input type="hidden" value="' . $num_compra . '" name="item['.$i.'][num_compra]" />
<input type="hidden" value="'.$plano.'" name="item['.$i.'][plano]">';
$i++;
?>
got that:
<html>
<input type="hidden" value="1111" name="item[0][num_compra]" />
<input type="hidden" value="aaaa" name="item[0][plano]" >
<input type="hidden" value="2222" name="item[1][num_compra]" />
<input type="hidden" value="bbbb" name="item[1][plano]" >
<input type="hidden" value="3333" name="item[2][num_compra]" />
<input type="hidden" value="cccc" name="item[2][plano]" >
quantidade de pares de input de acordo com o banco de dados.
<input type="submit">
</html>
After SUBMIT:
echo $_POST['item'];
Array ( [0] => Array ( [num_compra] => 1111 [plano] => aaaa )
[1] => Array ( [num_compra] => 2222 [plano] => bbbb )
[2] => Array ( [num_compra] => 3333 [plano] => cccc ) )
So far, so good, now the problem: I need to place a checkbox for each input
<input type="hidden" value="1111" name="item[0][num_compra]" />
<input type="hidden" value="aaaa" name="item[0][plano]" >
<INPUT TYPE="CHECKBOX" NAME="????" VALUE="?????"> CHECKBOX 1
<input type="hidden" value="2222" name="item[1][num_compra]" />
<input type="hidden" value="bbbb" name="item[1][plano]" >
<INPUT TYPE="CHECKBOX" NAME="?????" VALUE="?????"> CHECKBOX 2
<input type="hidden" value="3333" name="item[2][num_compra]" />
<input type="hidden" value="cccc" name="item[2][plano]" >
<INPUT TYPE="CHECKBOX" NAME="?????" VALUE="????"> CHECKBOX 3
and create an array only with checkbox=checked
CHECKBOX 3 checked
Array ( [0] => Array ( [num_compra] => 3333 [plano] => cccc ) )
CHECKBOX 2 and CHECKBOX 3 checked
Array ( [0] => Array ( [num_compra] => 2222 [plano] => bbbb )
[1] => Array ( [num_compra] => 3333 [plano] => cccc ) )
CHECKBOX 1 and CHECKBOX 3
Array ( [0] => Array ( [num_compra] => 1111 [plano] => aaaa )
[1] => Array ( [num_compra] => 3333 [plano] => cccc ) )
and at the end, use this array to do
UPDATE table SET status='1' WHERE num_compra = $num_compra AND plano = $plano;
What is the solution to this?
Can explain better?
– Papa Charlie
my doubt eh: which name and value should I assign to checkbox and how to write the php script to create the array with the data of each checkbox marked? Currently, I get an array with ALL data, even if I haven’t checked the checkbox.
– user15839