我已经从表单中输入了数据,但是输入为0。
我尝试使用数组输入数据,但是在数据库中输入了值0
视图
<div class="form-row">
<div class="col-md->
<?php foreach($komoditi->result_array() as $k): ?>
<p><?= $k['komoditi'] ?></>
<input type="hidden" name="id_bahan[]" value="<?= $k['id_bahan']; ?>">
<?php endforeach; ?>
</div>
<div class="col-md-2">
<?php foreach($komoditi->result_array() as $k): ?>
<input type="number" name="hargabahanpokok[]">
<?php endforeach; ?>
<div class="col-md-2">
<?php foreach($komoditi->result_array() as $k): ?>
<p>/<?= $k['satuan']; ?></p>
<?php endforeach; ?>
</div>
<input type="hidden" name="id_pasar[]" value="3">
<input type="hidden" name="status[]" value="1">
<input type="hidden" name="id_hargabahanpokok" value="<?php echo $satu['id_hargabahanpokok'];?>">
<input type="submit" name="simpan"value="Simpan">
型号
public function insert($data){
return $this->db->insert('hargabahanpokok',$data);
}
控制器
public function index(){
if($this->input->post('simpan')){
$id_pasar = $this->input->post('id_pasar');
$id_bahan = $this->input->post('id_bahan');
$hargabahanpokok = $this->input->post('hargabahanpokok');
$status = $this->input->post('status');
$query = $this->db->query("SELECT count('id_bahan') as jml from namabahan")->result_array();
$max = intval($query[0]['jml']);
$id_pasar = 3;
$id_bahan = $this->input->post('id_bahan');
$hargabahanpokok = $this->input->post('hargabahanpokok');
$status = 1;
for($i=0; $i<$max; $i++){
$result = array(
`id_pasar` => 3,
`id_bahan` => $id_bahan[$i],
`hargabahanpokok` => $hargabahanpokok[$i],
`status` => 1,
);
$this->ModelTaraju->insert('hargabahanpokok', $result);
}
}
}
我希望:
进入数据库的数据是在“ hargabahanpokok”数据库1000中输入“ hargabahanpokok” 1000时。
id_bahan根据表bahan中的id_bahan进入数据库
ID_pasar根据表pasar中的ID_pasar进入数据库
答案 0 :(得分:0)
在插入之前,先在数据数组中打印值,然后查看其中的值,例如
public function insert($data){
print_r($data);exit;
$this->db->insert('hargabahanpokok',$data);
}