php - Codeigniter JOIN multiple tables -


i'm having little trouble in retrieving data in multiple tables using codeigniter.

this code i'm using retrieve data in model working well.

function retrieve_experience($alumni_id) { $this->db->select('*'); $this->db->from('experience'); $this->db->where('alumni_id',$alumni_id); $query = $this->db->get(); return $query;   }  function retrieve_education($alumni_id) { $this->db->select('*'); $this->db->from('education'); $this->db->where('alumni_id',$alumni_id); $query = $this->db->get(); return $query; } 

now tried using simplified code fails display data. here code in model

function retrieve_all_data($alumni_id) { $this->db->select('*'); $this->db->from('experience'); $this->db->join('education','education.alumni_id=experience.alumni_id'); $this->db->where('experience.alumni_id',$alumni_id); $query=$this->db->get(); return $query->result_array(); } 

in controller, used code retrieving data in model

function display() { $alumni_id = $this->session->userdata('alumni_id'); $data['all_data'] = $this->alumni_model->retrieve_all_data($alumni_id); $data['main_content'] = 'alumni_home'; $this->load->view('includes/template', $data); } 

and display used code

foreach($all_data $results) { /** data experience table **/ $results['company_name'];  $results['company_address']; /** data education table **/ $results['school_name']; $results['field_of_study']; } 

i cant display @ all. please

try below code,

i believe you'll want this:

function retrieve_all_data($alumni_id) {   $this->db->select("e.*,edu.*");   $this->db->from("experience e");   $this->db->join("education edu", "edu.alumni_id = e.alumni_id",'left');   $this->db->where('e.alumni_id',$alumni_id);   $this->db->group_by('e.exp_id');   $query = $this->db->get();   return $query->result_array(); } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -