Ниже приведен мой контроллер < /p>
Код: Выделить всё
function add_invoice()
{
$customer = $this->input->post('customer');
$date = date("Y-m-d",strtotime($this->input->post('date')));
$grandtotal = $this->input->post('grandtotal');
$ref = rand(1111111111, 9999999999);
$medicine = $this->input->post('medicine');
$quantity = $this->input->post('quantity');
$subtotal = $this->input->post('subtotal');
foreach ($medicine as $key => $val) {
$data[] = array(
'customer' => $customer,
'date' => $date,
'grandtotal' => $grandtotal,
'ref' => $ref,
'medicine' => $val,
'quantity' => $quantity[$key],
'subtotal' => $subtotal[$key],
);
}
$this->my_model->decrement_item($medicine, $quantity);
$this->db->insert_batch('table_invoice', $data);
}
< /code>
И это моя модель: < /p>
function decrement_item($medicine, $quantity)
{
$q = "UPDATE table_med SET stock = stock - ? WHERE medicine = ?";
$this->db->query($q, [$quantity, $medicine]);
if ($this->db->affected_rows() > 0) {
return TRUE;
} else {
return FALSE;
}
}
Я знаю, что я должен повернуть параметр в Array. Но я не знаю как?
Подробнее здесь: https://stackoverflow.com/questions/517 ... rs-an-inva