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
normally 'id' field is set with auto_increment and set primary which is unique and not repeatable. So there is not problem to worry about existing.
However, in your case I think you are not using it as a 'unique field'.
Let me give you an example.
Here I have a table name 'fruits'
++++++++++++++++++++++++++++++++++++
ငfruit_id | int (primary)
name | text
id | int
++++++++++++++++++++++++++++++++++++++
in your model
function checkId($id)
{
$query=$this->db->get_where('fruits',array('id'=>$id)); //check if 'id' field is existed or not
if($query!=null) // id found stop
{
return FALSE;
}
else // id not found continue..
{
$data = array(
'fruit_id' => $fruit_id ,
'name' => $name ,
'id' => $id
);
$this->db->insert('fruits', $data);
}
}