简体   繁体   中英

inserting data into database with condition/ codeigniter

I am a beginner in CodeIgniter and I want to insert a data in codeigniter with a where clause. Something like a query like this:

insert into tbl_check_up (bill_id) values ("bill_id") where check_up_id = "'.$check_up_id.'" ;

how can i convert it into codeigniter

Here is my codeigniter model:

var $tbl_check_up = 'tbl_check_up';

public function save_bill_checkup($check_up_id,$data) {
        $this->db->insert($this->tbl_check_up,$data);
        return $this->db->insert_id();
    }

Here is my controller :

public function bill_id() {
     $check_up_id = $this->input->post('check_up_id');
     $data1 = array(
            'bill_id'   => $bill_id
         );
     $insert1 = $this->billing_model->save_bill_checkup($check_up_id,$data1);
}

Instead of insert, use update query.

$data = array(
           'bill_id'   => $bill_id
        );

$this->db->where('check_up_id', $check_up_id);
$this->db->update('tbl_check_up ', $data); 

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