O'Brien O'Brien - 1 month ago 16
MySQL Question

Codeigniter: Two table query

I have two tables that I want to query. One table has records from the clinic while the other has records from the lab. This results in(Message: Trying to get property of non-object). What am I missing out?

I want to see the PID which are in clinic table but not in lab table.

My controller:

function queries(){
$data['results'] = $this->main_model->queries();
$this->load->view('queries', $data);

}


My Model:

function queries(){

$this->db->select('*');
$this->db->from('clinic');
$this->db->where('participantID NOT IN (SELECT participantID FROM lab)', NULL, FALSE);
$results = $this->db->get();
return $results;
}


Finally, my view:

<?php

foreach($results as $row){


echo " <tr > <td> $row->participantID </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td></tr>";


}

?>

Answer

Controller:

function getall(){      
$this->load->model('result_model');
$data['query'] =$this->result_model->result_getall();
print_r($data['query']);
die();
$this->load->view('result_view', $data);
}

Model:

function result_getall(){

$this->db->select('*');
$this->db->from('tblanswers');
$this->db->join('credentials', 'tblanswers.answerid = credentials.cid', 'left'); 
$query = $this->db->get();
return $query->result();

}

view:

 <?php foreach ($query as $row): ?>      

     <?php echo $row->answerA;?><br>

     <?php endforeach; ?>  
Comments