How to check if id already exists - codeigniter

前端 未结 7 1402
独厮守ぢ
独厮守ぢ 2021-02-09 06:56

i am trying to check if an id in the database already exists and if it does not then only insert that id and not the other ones that exist

I have tried to do a where sta

7条回答
  •  孤街浪徒
    2021-02-09 07:31

    $ql = $this->db->select('id')->from('testing')->where('id',$id)->get();
    
    if( $ql->num_rows() > 0 ) {} else {
        $a = array('id' => $id, 'message' => $message);
        $this->db->insert('testing', $a);
    }
    

    This should do it.

提交回复
热议问题