How to check if id already exists - codeigniter

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

    You have a logic issue with your code that you need to fix.

    In your code, you save the result from your query as $q = $this->db->get('testing'), and $q will always evaluate to true regardless of the number of rows your return.

    You need to check the number of rows using $query->num_rows() > 0 and then the rest of you code will behave as you expect.

    For more details, see: http://ellislab.com/codeigniter/user-guide/database/results.html

提交回复
热议问题