简体   繁体   中英

insert and update at the same time with codeigniter

I have another problem again on querying in CodeIgniter, I'll try to insert and update a "comment" on my website, but it's not working yet.

Here's my code :

on the Models (news_model.php)

public function simpan_komentar() {
 $data = array(
    'noid' => $_POST['noid'],
    'kategori' => $_POST['kategori'],
    'nama' => $_POST['nama'],
    'pekerjaan' => $_POST['pekerjaan'],
    'detail' => $_POST['detail'],
    'created_at' => date('Y-m-d h:i:s'),

    );
 $data1 = array(
   'komentar' => 'komentar + 1',
  );
 $this->db->insert('komentar',$data);
 $this->db->update('news',$data1);
 }

The insert query is working, but the update query didn't work Can you tell me where's my fault? Thanks

Try this

$this->db->set('komentar', 'komentar+1', FALSE);
//add your where condition if any
$this->db->update('news');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM