单击提交 btn 时,我想将多个数据插入多行
下面是我的html表单
<?php echo form_open('daily_shop_performance/insert_missing_records');?>
<table class="table" style=" width:100%; ">
<thead>
<tr>
<th>Days</th>
<th>Shop ID</th>
<th>Date</th>
<th>Takings</th>
<th>Payout</th>
<th>Actual Slippage</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>FRI</b></td>
<td><?php echo form_input('BDP_COST_CENTRE_NUMBER', set_value('BDP_COST_CENTRE_NUMBER', ''), 'class=span1' ); ?></td>
<td><?php echo form_input('BDP_DATE', set_value('BDP_DATE', ''), 'class=span2' ); ?></td>
<td><?php echo form_input('BDP_TAKE', set_value('BDP_TAKE', ''), 'class=span2' ); ?></td>
<td><?php echo form_input('BDP_PAYOUT', set_value('BDP_PAYOUT', ''), 'class=span2' ); ?></td>
<td><?php echo form_input('BDP_ACTUAL_SLIPPAGE', set_value('BDP_ACTUAL_SLIPPAGE', ''), 'class=span2' ); ?></td>
</tr>
<tr>
<td><b>SAT</b></td>
<td><?php echo form_input('BDP_COST_CENTRE_NUMBER1', set_value('BDP_COST_CENTRE_NUMBER1', ''), 'class=span1' ); ?></td>
<td><?php echo form_input('BDP_DATE1', set_value('BDP_DATE1', ''), 'class=span2' ); ?></td>
<td><?php echo form_input('BDP_TAKE1', set_value('BDP_TAKE1', ''), 'class=span2' ); ?></td>
<td><?php echo form_input('BDP_PAYOUT1', set_value('BDP_PAYOUT1', ''), 'class=span2' ); ?></td>
<td><?php echo form_input('BDP_ACTUAL_SLIPPAGE1', set_value('BDP_ACTUAL_SLIPPAGE1', ''), 'class=span2' ); ?></td>
</tr>
<tr>
<td><?php echo form_submit('submit', 'Next', 'class="btn btn-large"', 'type="button"'); ?></td>
</tr>
</table>
<?php echo form_close();?>
我的插入语句将每条记录插入为数组
这工作正常,但我不确定如何只插入带有数据的表单字段并忽略空的表单字段
Below is my insert query
public function insert_missing_records()
{
$insert_data = array(
array(
'BDP_ID'=> '',
'BDP_COST_CENTRE_NUMBER'=> $this->input->post('BDP_COST_CENTRE_NUMBER'),
'BDP_DATE' => $this->input->post('BDP_DATE'),
'BDP_DAY_CODE'=> '1',
'BDP_TAKE'=> $this->input->post('BDP_TAKE'),
'BDP_PAYOUT'=> $this->input->post('BDP_PAYOUT'),
'BDP_ACTUAL_SLIPPAGE'=> $this->input->post('BDP_ACTUAL_SLIPPAGE'),
'BDP_PROCESS_DATE'=> $this->performance_m->date(),
'BDP_RUN_DATE'=> $this->performance_m->date(),
'BDP_CREATED_BY'=> $this->session->userdata('BL_USERNAME'),
'BDP_SOURCE'=> 'M',
'BDP_UPDATE_DATE'=> '',
'BDP_UPDATED_BY'=> $this->session->userdata('BL_USERNAME')
),
array(
'BDP_ID'=> '',
'BDP_COST_CENTRE_NUMBER'=> $this->input->post('BDP_COST_CENTRE_NUMBER1'),
'BDP_DATE' => $this->input->post('BDP_DATE1'),
'BDP_DAY_CODE'=> '2',
'BDP_TAKE'=> $this->input->post('BDP_TAKE1'),
'BDP_PAYOUT'=> $this->input->post('BDP_PAYOUT1'),
'BDP_ACTUAL_SLIPPAGE'=> $this->input->post('BDP_ACTUAL_SLIPPAGE1'),
'BDP_PROCESS_DATE'=> $this->performance_m->date(),
'BDP_RUN_DATE'=> $this->performance_m->date(),
'BDP_CREATED_BY'=> $this->session->userdata('BL_USERNAME'),
'BDP_SOURCE'=> 'M',
'BDP_UPDATE_DATE'=> '',
'BDP_UPDATED_BY'=> $this->session- >userdata('BL_USERNAME')
)
);
$insert = $this->db->insert_batch('WHOUSE1.DLY_BWR_MAN_PERFORMANCE', $insert_data);
echo '<pre>' .$this->db->last_query(). '</pre>';
return $insert;
}
如果有人可以提供帮助,我会很高兴。谢谢