【发布时间】:2015-07-13 19:34:09
【问题描述】:
我有一个包含 2 个字段的表单。
<td class="left"><input style=" width: 30%; text-align: center;" type="text" name="name[]" value="<?php echo $geo_zone['name']; ?>" /></td>
<td class="left"><input style=" width: 30%; text-align: center;" type="email" name="email[]" value="<?php echo $geo_zone['email']; ?>" /></td>
如果我 print_r 我的数组,我会得到完美的结果。像这样
$name = $this->request->post['name'];;
$email = $this->request->post['email'];;
但我想要的是继续在数据库中插入这两个值,直到数组为空($name 和 $email)。为此,我尝试了每个循环,但它只在数据库中插入一行。
foreach( $name as $key => $n ) {
$this->data['geo_zone_id']=$this->model_module_shipping_pools->Get_geo_zone_id($n);
$geo_zone_id=$this->data['geo_zone_id'];
$geo_zone_id=$geo_zone_id[0]['geo_zone_id'];
$this->model_module_shipping_pools->drop_data();
$email=$email[$key];
$this->model_module_shipping_pools->insertData($geo_zone_id,$email);
}
【问题讨论】:
-
but what i want is to keep inserting these two values in database until arrays are empty ($name and $email).你能详细解释一下吗? -
@anantkumarsingh 实际上我的表单是根据数据库中的行动态创建的,因此这两个电子邮件和姓名数组可能包含多个值。你在 html 中只看到两个输入字段,但它们是在运行时生成的,我使用 name[] 和 email[] 来存储多个值
-
@anantkumarsingh 知道为什么我的循环只运行一次
标签: php sql model-view-controller opencart