O'Brien O'Brien - 1 year ago 103
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->where('participantID NOT IN (SELECT participantID FROM lab)', NULL, FALSE);
$results = $this->db->get();
return $results;

Finally, my view:


foreach($results as $row){

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



Answer Source


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


function result_getall(){

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



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

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

     <?php endforeach; ?>  
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download