当我选择其中一个复选框时,我遇到了问题。如果未选中复选框,如何停止 foreach 运行?请检查我的代码以解决问题。
我想要一个未选中数据的条件。
这是我的控制器:
public function create_cargo_manifest(){
$core_model = new Core_m;
$core_model->save_cargo_details();
redirect('core/cargo_lookup/','refresh');
}
这是我的模型:
function save_cargo_details() {
$data = array();
$waybillno = $this->input->post('waybillno');
$quantity = $this->input->post('quantity');
$waybilldate = $this->input->post('waybilldate');
$declared_value = $this->input->post('declared_value');
$consignee = $this->input->post('consignee');
$count = count($waybillno);
if(empty($waybillno)){
}else{
for ($i = 0; $i < $count; $i++) {
$data = array(
'waybillno' => $waybillno[$i],
'quantity' => $quantity[$i],
'waybilldate' => $waybilldate[$i],
'declared_value' => $declared_value[$i],
'consignee' => $consignee[$i],
);
// SUBRACT REMAINING_QUANTITY //
$this->db->select('wd.remaining_qty');
$this->db->where('wd.waybillno',$waybillno[$i]);
$this->db->from(self::WAYBILL_DETAILS_TABLE. " as wd");
$query = $this->db->get()->row();
$qty = $query->remaining_qty;
$remaining = $qty - $data['quantity'];
$this->db->where('waybillno',$waybillno[$i]);
$this->db->set('remaining_qty',$remaining);
$this->db->update(self::WAYBILL_DETAILS_TABLE);
// INSERT DATA //
$this->db->insert('sys_cargodetails', $data);
}
}
}
这是我的看法:
<?php foreach($waybill_header as $waybill_header) { ?>
<?php echo form_open('core/create_cargo_manifest'); ?>
<tr style="text-align: center;">
<td><input type="checkbox" name="waybillno[]" value="<?php echo $waybill_header->waybillno; ?>"></td>
<td><?php echo $waybill_header->waybillno; ?><input type="hidden" ></td>
<td><?php echo $waybill_header->waybilldate; ?><input type="hidden" value="<?php echo $waybill_header->waybilldate; ?>" name="waybilldate[]"></td>
<td><input type="text" size="5" value="<?php echo $waybill_header->remaining_qty; ?>" name="quantity[]">
<input type="hidden" value="<?php echo $waybill_header->declared_value; ?>" name="declared_value[]">
<input type="hidden" value="<?php echo $waybill_header->consignee; ?>" name="consignee[]">
</td>
</tr>
<?php } ?>
</table>
<input type="submit" value="Save"><button id="button_cancel" type="button">Close</button>
<?php form_close(); ?>