为了账号安全,请及时绑定邮箱和手机立即绑定

PHP 代码点火器

PHP 代码点火器

PHP
眼眸繁星 2023-09-22 16:44:38
我正在使用 Codeigniter。我的表单有多行,每行具有相同的字段名称。您能帮助我如何通过循环将其保存在数据库中吗?我收到错误错误号:1048 列“sn_unit”不能为空请看下面的代码。预先感谢您的帮助。这是视图<?php for ($i = 1; $i <= $number_to_check; $i++) {?><hr><div class="row">   <div class="col-xl-4">       <div class="mb-3">          <label class="form-label"><strong><?php echo $i;?></strong></label>          <input type="text" class="form-control" name="sn_unit[]" placeholder="Unit Serial Number" required>       </div>    </div></div><?php }?>这是控制器for ($i = 1; $i <= count($this->input->post('sn_unit')); $i++) {   $sn_unit = $this->input->post('sn_unit[$i]');                 $chk = $this->auth->saveItemReport();}
查看完整描述

1 回答

?
蛊毒传说

TA贡献1895条经验 获得超3个赞

您可以简单地使用 foreach 循环遍历所有值。


foreach($this->input->post('sn_unit') as $key => $value)

   $sn_unit = $value;

   $chk = $this->auth->saveItemReport(); 

}

如果您仍然喜欢使用 for 循环;永远记住数组从 0 索引开始,所以:


$units = $this->input->post('sn_unit');

for ($i = 0; $i < count($units); $i++) {

   $sn_unit = $units[$i];   

   $chk = $this->auth->saveItemReport();

}


查看完整回答
反对 回复 2023-09-22
  • 1 回答
  • 0 关注
  • 35 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信