I would like to use the $data['main']
and get a specific row or data from it which is: extra_id
I would use extra_id
for another function.
I tried accessing the data from the $data['main']
just like what I did on the view of the other page which is: $extra_id = $main->result()->extra_id;
Unfortunately, it did not work.
controller:
public function viewData($id)
{
$this->load->model('myModel');
$data['main'] = $this->MyModel->getMainData($id);
$extra_id = $main->result()->extra_id; //error here. undefined variable main.
$data['extra'] = $this->MyModel->getExtraData($extra_id);
$this->load->view('view',$data);
}
model:
public function getMainData($id) {
$this->db->select('main.id as extra_id');
$this->db->select('main.*');
$this->db->select('extra.*');
$this->db->from('main');
$this->db->join('extra', 'extra.main_id = main.id');
$query = $this->db->get();
return $query;
}