I have an update function in my Model which I call from My controller as
if($_POST)
{
$this->User_model->update('user_about',$_POST,$this->session->userdata['id']);
}
takes three parameters, table name, post data and user id. The function is defined in the Model as
public function update($table,$data,$id)
{
$row=$this->db->select('*')->from($table)->WHERE('user_id',$id)->row();
if($row)
{
$this->db->WHERE('user_id',$id)->UPDATE($table,$data);
}
else
{
$data['user_id']=$id;
$this->db->insert($table,$data);
}
}
What I am doing here is checking if the record of particular user doesn't exist it should insert, otherwise update. Works like a charm
Question
Is there a way to skip the IF condition block?. Is there any provision in query builder which performs the check itself?