Adding string fields to the table in update

时间:2015-11-12 06:33:02

标签: php codeigniter

In CodeIgniter how to add string to fields?

$this->db->where('acctg_store_id',$data['acc_store_id']);
    $this->db->set('dscr',dscr . $data['desc']);
    $this->db->set('stat',$data['val_selected']);
    $this->db->update('acctg_store',$db)

$this->db->where('acctg_store_id',$data['acc_store_id']);

dscr is in text and in update, I want to add string to dscr

3 个答案:

答案 0 :(得分:1)

我认为您希望通过使用旧值dscr附加新值来更新字段dscr。因此,您可以在dscr

中获取当前值
$this->db->where('acctg_store_id',$data['acc_store_id']);
$res = $this->db->get("acctg_store");
$row = $res->row();
$dscr = $row->dscr;

然后在更新中附加此值$dscr

$this->db->where('acctg_store_id',$data['acc_store_id']);
$this->db->set('dscr', $dscr . "/". $data['desc']);
$this->db->set('stat',$data['val_selected']);
$this->db->update('acctg_store',$db)

答案 1 :(得分:0)

就这样做

$data = array(
        'dscr' => $data['desc'],
        'stat' => $data['val_selected'],
);

$this->db->where('acctg_store_id', $data['acc_store_id']);
$this->db->update('acctg_store', $data);

Updating Data

答案 2 :(得分:0)

试试这个

$this->db->where('acctg_store_id',$data['acc_store_id']);
$dscr="dscr" . $data['desc'];
$this->db->set('dscr',$dscr);
$this->db->set('stat',$data['val_selected']);
$this->db->update('acctg_store',$db);