更新时间:2023-12-04 12:48:46
最后一次修复it.here是我的意见
at last i fix it.here is my view
<?php for($i = 1; $i <=10; $i++):?>
<tr>
<td>
<?php echo $i;?>
</td>
<td>
<input type="text" name="code[]" value="<?php echo '';?>" id="code" />
</td>
<td>
<input type="text" name="rate[]" value="<?php echo '';?>" id="rate" />
</td>
<td>
<input type="text" name="quantity[]" value="<?php echo '';?>" id="quantity" />
</td>
</tr>
<?php endfor;?>
这里是我的控制器
if (empty($_POST))
{
$this->index();
}
else
{
//insert to database
$this->load->model('buy_product_model');
$data= $this->buy_product_model->add_product();
//echo "success";
$this->index();
}
模型//
$data = array();
$todayDate = date('Y-m-d');
for($i = 0; $i < count($_POST['code']); $i++)
{
if($_POST['code'][$i] != '')
{
$data[] = array(
'code' => $_POST['code'][$i],
'shop' => $_POST['shop'],
'rate' => $_POST['rate'][$i],
'quantity' => $_POST['quantity'][$i],
'total' =>( $_POST['rate'][$i]*$_POST['quantity'][$i]),
'date' => $todayDate
);
}
}
$dataCount = count($data);
if($dataCount)
{
$this->db->insert_batch('purchase', $data);
}
return $dataCount;