我有兩個表:items_tbl
和request_tbl
:笨我怎樣才能在項目表更新數量字段當用戶提交請求,請求表
items_tbl
:
| item_id | item_name | quantity |
request_tbl
:
| request_id | item_id | quantity_requested |
request_tbl
具有item_id
作爲ForeignKey。如何通過$quantity - $quantity_requested
更新物料表中的數量字段?當用戶使用codeigniter
向請求表提交請求時?
MyController.php
:
function outward_items($request_id){
$this->load->model('request');
$ord_id = $this->request->insert_request($requests);
$outward = array(
'quantity_left' => $this->input->post('quantity_left'),
'item_id' => $this->input->post('item_id'),
);
$cust_id = $this->request->insert_outward($outward);
$data['requests'] = $this->request->get_requests($request_id);
$data['main_content'] = 'backend/requests/requests';
$data['title'] = 'Outwards';
$this->load->view('includes/template', $data);
}
你熟悉的控制器和模型和需要幫助,在短短的SQL查詢? – mrid
是的先生我需要的控制器和模型 – turaco
爲什麼不使用mysql觸發器,這很容易 – Bira