0

我有一个带有 uniqueID/PrimaryKe (OrderNumber) 的数据库记录

我想用相同的 PrimaryKey OrderNumber 的新数据更新记录。

我的控制器是:

 $data = array(
      'CustomerName' =>  $this->input->post('customer'),
      'CustomerAccountCode' =>  $this->input->post('accountcode'),
      'PeriodStart' =>  substr($this->input->post('period'), 0,10),
      'OrderUnitOfMeasure' =>  $this->input->post('buom'),
      'CreditLimit' =>  $this->input->post('creditlimit'),
      'BalanceBeforeOrder' =>  $this->input->post('currentbalance'),
      'BalanceAfterOrder' =>  $this->input->post('newbalance'),
      'OrderLines' =>  $this->input->post('orderlines'),
      'TotalCost' =>  $this->input->post('grandtotal'),
      'AverageDiscount' =>  $this->input->post('avediscount'),
      'TotalCubes' =>  $this->input->post('grandtotalcubes'),
      'TreatedCubes' =>  $this->input->post('grandtotaltreatedcubes'),
      'SpecialComments' =>  $this->input->post('specialcomments'),
      'CustomerReference' =>  $this->input->post('customerref'),
      'ordernumber' =>  $this->input->post('ordernumber')
      );

    $this->sales_model->update_order_data($data);

我的模型是:

function update_order_data($q){
    $this->db->where('CustomerOrderID', 'OrderNumber'); //ordernumber being post input ordernumber in array
    $query = $this->db->update('Customer_Order_Summary');
}

所以我想要的是:

update 'Customer_Order_Summary' 
set 'CustomerName'="$this->input->post('customer')",
set 'CustomerAccountCode'="$this->input->post('accountcode')",
//rest of set statements for each column and corresponding post
where 'CustomerOrderID'='OrderNumberInArray'//(post value)

此更新声明不起作用,任何指针将不胜感激。

一如既往地感谢,

4

2 回答 2

2

从您的数组中删除 'ordernumber'$data并单独传递

$this->sales_model->update_order_data($this->input->post('ordernumber'),$data);‌

查询应该像

function update_order_data($key,$q){
 $this->db->where('CustomerOrderID', $key);
 $query = $this->db->update('Customer_Order_Summary',$q);
}
于 2013-05-14T14:08:20.990 回答
2

尝试:

function update_order_data($q)
{
    $this->db->where('CustomerOrderID', $q['OrderNumber']);
    $this->db->update('Customer_Order_Summary',$q);
    return $this->db->affected_rows();
}

注意:通常,在更新函数中,我有 2 个参数,例如:

function update_something($pk,$data)
{
   $this->db->where('primary_key', $pk);
   $this->db->update('database_table',$data);
   return $this->db->affected_rows();
}
于 2013-05-14T14:14:50.653 回答