I'm passing the User_name with reference to that I have to fetch the visit_id which is in the third table, since my method is little messy can anyone tell how to achieve this using Codeigniter sub-query?
public function fetch_patient_bill($user_name) {
$this->db->select('id');
$this->db->from('user');
$query = $this->db->where('user_name', $user_name);
$result = $query->get();
foreach ($result->result() as $user) {}
$user_id = $user->id;
$this->db->select('id');
$this->db->from('patient_registration');
$query = $this->db->where('user_id', $user_id);
$result = $query->get();
foreach ($result->result() as $registration) {}
$registration_id = $registration->id;
$this->db->select('id');
$this->db->from('patient_visit');
$query = $this->db->where('patient_id', $registration_id);
$result = $query->get();
foreach ($result->result() as $visit) {}
$visit_id = $visit->id; //i want to fetch this id
}