有没有一种方法可以将文本框和文本框的数组从视图发送到控制器(CodeIgniter)

时间:2020-05-01 10:47:08

标签: codeigniter view controller

我正在使用CodeIgniter构建店面,其中在数据库视图中以复选框显示数据库中的项目列表。用户将选择项目并输入其数量。当用户单击“发送”时,用户设置的项目列表及其数量将被提交到数据库。

这是查看代码:

 <table>
                  <thead>
                  <tr>
                      <th>SN</th>
                      <th>Product</th><th>Tick</th>
                      <th>quantity</th>

                  </tr>
                  </thead>
                    <tbody>
                    <?php
                    $i=0;
                    foreach($it as $r):
                    $i++;
                    ?>
                    <tr><td><?php echo $i; ?></td>
                        <td><?=$r['Item'];?></td>
                        <td>
                        <input type="checkbox" name="item[]" value="<?=$r['Item']?>" /></td>
                        </td> 
                        <td>
                            <input type="number" name="qty[]" />
                           </td>
                       </tr> <?php endforeach?>
                    <tr><td colspan="3">
                            <input type="submit" name="btnub" value="Send Order" /></td></tr>
                    </tbody>
                </table>

<!-- Controller Code (CodeIgniter) -->

<!-- CodeIgniter Controller Code to harvest the Order  -->

 if (isset($_POST['btnub'])) {
            foreach($_POST['item'] as $key=>$item) {
                for ($i = 1; $i < 2000; $i++) {
                    $h = "qty" . $i;
                        $qty = $this->input->post[$h];
                    }
                    $tt = array(
                        'item' => $item,
                        'Qty' => $qty,
                    );
                    $this->tranmodel->insertthing("cuzorder", $tt);
            }  }

0 个答案:

没有答案