How to check if id already exists - codeigniter

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

    You need to select the id's in your MYSQL table with the id you want to check and then count the rows. If the row count is 0 then the id doesn't exist.

         $query = mysql_query("SELECT * FROM     your_table WHERE id='$id'");
         $count = mysql_num_rows($query);
         If($count!=0){
         // id exists
         } else {
         // id doesn't exist
         }
    
    0 讨论(0)
提交回复
热议问题