$sql = "select * from instalmentsdetails_ where studentFeeId='$savestudentfees' AND instalmentName='$instlnamefdtls'";
$query = $this->db->query($sql);
if($query->num_rows() > 0){
echo($id);
$this->db->where('instalmentsDetailsId',$id);
$this->db->update('instalmentsdetails_',$instldata);
}else{
echo($id);
$id='';
echo($id);
$sql= "INSERT INTO instalmentsdetails_` (`instalmentsDetailsId`, `studentFeeId`, `instalmentName`, `amount`, `dueDate`, `status`) VALUES ('$id', '$savestudentfees', '$instlnamefdtls', '$amtfdtls', '2011-10-06', '1')";
$id=$this->db->insert_id();
$query = $this->db->query($sql);
return $query;
}
return $id;
This query first checks if there are any rows present, if there is, it is going to update the old record, otherwise it is going to create a new record, but for some reason it does not work as expected even when the query returns num_row() > 0
.It's a model in codeigniter