1
Captures in an array the values received via checkbox marked post, these checkboxes have the values equal to the names of the table fields, need to make a query with while and print the fields referring to array:
<?php
$campos = '`'.implode('`, `', $_POST['check']).'`';
$sql = mysql_query("SELECT id,$campos FROM chamado where status = 1");
while($busca=mysql_fetch_array($sql)){
?>
<tr class="odd gradeX">
<td width="2%"><?php echo $busca['id'];?></td>
<?php
foreach ($quantidade_item as $tags) {
echo '<td width="2%">'.$busca[$tags].'</td>';
}
?>
</tr>
<?php
}
?>
What happens is that when executing the code, if it is verified that only a checkbox has been marked, the listing appears normally, but, if you check more than one checkbox, the listing displays only the data of the first column, the other columns return me Undefined index -
I didn’t quite understand the problem. You can explain it better/in other words?
– Sergio
Yes, you failed to report the problem. What happens is that when executing the code, if it is verified that only a checkbox has been checked, the listing appears normally, but if you check more than one checkbox, the listing displays only the data from the first column, the other columns return me Undefined index
– sNniffer
Okay, and what gives
var_dump($_POST['check']);
if you put it in the first line of that code that you show`– Sergio
Sorry for the delay, I had problems with my hosting, well, when executing the code and inform the line you said returns:
array(3) { [0]=> string(8) "cpf_cnpj" [1]=> string(13) "data_cadastro" [2]=> string(10) "id_cliente" }
, and in the example I marked 3 check– sNniffer
and if you check only one checkbox as the
var_dump
? puts your HTML too to understand better. You don’t need``` in $fields.– Sergio
Just a check
array(1) { [0]=> string(8) "cpf_cnpj" }
, when checking the query works normally, when passing more checks of the undefined variables and returns in the table only the values of a column– sNniffer
I don’t quite understand your problem but I have a tip for you, don’t use mysql_query because it is obsolete, I advise you to use PDO or Mysqli.
– Kayo Bruno