How to check if id already exists - codeigniter

前端 未结 7 1417
独厮守ぢ
独厮守ぢ 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:26

    You should try like this:

    public function record_exists(){
       $exists = $this->db->get_where('table_name', array('id' => $id));
       if($exists->num_rows() > 0 ){
           echo "Some message";
           return false;
       }else{
          // Insert your data into the database...
       }
    }
    

提交回复
热议问题