使用数组在包含未指定数量的输入字段的循环中插入数据


Inserting data using arrays within a loop of unspecified number of input fields

这是一段代码,它以只手动插入最后一个字段的形式显示表。

填写后,您应该继续将表单保存到数据库中,但由于没有特定数量的输入字段(因为它们会有所不同),因此我需要使用数组来捕获所有数据。

$quam = mysqli_query('select * from locstock where loccode="' . $loc . '"') or die(mysqli_error());
    while ($row = mysqli_fetch_array($quam)) {
        echo '<tr><td>' . getItemcode($row['itemid']) . '</td>';
        echo '<td>' . getItemname($row['itemid']) . '</td>';
        echo '<input type="hidden" value="' . ($row['itemid']) . '" name="itemid[0][]">';
        echo '<td>' . ($row['quantity']) . '</td>';
        echo '<input type="hidden" value="' . ($row['quantity']) . '" name="iquant[0][]">';
        echo '<td><input type="text" title="Enter Manual Count" placeholder="Enter Manual Count" name="tally[0][]"></td>';
        echo '</tr>';
    } 

如何检索数据?

您可以轻松地count()您的INPUT字段数据。由于您的值是array->name="iquant[0][]"的一部分,因此可以轻松处理它们。提交表单后查看print_r($_POST);的输出。