我有这样的表格
<form action="insert_controllo.php" method="POST">
<table>
<th>Macchina</th>
<th>Dispositivo</th>
<th>Descrizione</th>
<th>OK</th>
<th>NOK</th>
<th>PARZ</th>
<th>NA</th>
<th>Note</th>
<?while($row = mysql_fetch_array($risultato)){
echo '<tr><td> <input class="hide" type= "text" name="elements['.$count.'][macc]" value ="'.$row["macc"].'" readonly>
</td><td> <input class="hide" type= "text" name="elements['.$count.'][iddispsic]" value ="'.$row["iddispsic"].'" readonly>
</td><td> <input class="hide" type= "text" name="elements['.$count.'][descgen]" value ="'.$row["descgen"].'" readonly>
</td><td> <input type= "radio" name="elements['.$count.'][chk1][]" value ="OK" checked>
</td><td> <input type= "radio" name="elements['.$count.'][chk1][]" value ="NOK">
</td><td> <input type= "radio" name="elements['.$count.'][chk1][]" value ="PARZ">
</td><td> <input type= "radio" name="elements['.$count.'][chk1][]" value ="NA">
</td><td> <input type="text" name="elements['.$count.'][note]" placeholder = "Note">
</td></tr>';
$count ++;
}?>
</table>
<button class="bottone" name='submit' type='submit'>Concludi</button>
在“ insert_controllo.php”页面中,如果我print_r($_POST);
可以以正确的方式看到所有变量
<!-- POST: Array
(
[elements] => Array
(
[0] => Array
(
[macc] => 09
)
[1] => Array
(
[iddispsic] => 8
[macc] => 09
[descgen] => Comandi di emergenza
[chk1] => Array
(
[0] => OK
)
[note] =>
)......
我正在尝试检索这样的变量
for($i=0; $i<count($_POST['elements']); $i++){
$macc = $_POST['elements']['macc'];
$dispsic = $_POST['elements']['iddispsic'];
$descgen = $_POST['elements']['descgen'];
$chk1 = $_POST['elements']['chk1'];
$note = $_POST['elements']['note'];
echo $macc;
echo $dispsic;
echo $descgen;
echo $chk1;
echo $note;
var_dump($macc);
}
}
但是在var_Dump中我只得到NULL值。 我需要将它们插入我的数据库表中 有人能帮我吗? 非常感谢 最好的问候
答案 0 :(得分:0)
尝试foreach循环
foreach ($_POST['elements'] as $element) {
$macc = $element['macc'];
$dispsic = $$element['iddispsic'];
$descgen = $element['descgen'];
$chk1 = $element['chk1'];
$note = $element['note'];
}
}
The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable.