How to delete data From database Using CodeIgniter?
Answer (1)
Use follow code for delete operation in CodeIgniter.
StudentController class
function delete_student(){
$student_id = $this->input->get("studentId");
$result = $this->StudentModel->delete_student($student_id);
if($result)
redirect(base_url."StudentController/studentlist");
}
StudentModel class
//function to Delete selected record from table name students
function delete_student($id){
$this->db->where("student_id", $id);
$this->db->delete("students");
if($this->db->affected_rows()){
return true;
}
}
}