我有两个表要查询。一张表包含诊所的记录,另一张表包含实验室的记录。这会导致(消息:尝试获取非对象的属性)。我错过了什么?
我想查看临床表中但实验室表中没有的 PID。
我的 Controller :
function queries(){
$data['results'] = $this->main_model->queries();
$this->load->view('queries', $data);
}
我的模型:
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;
}
最后说一下我的看法:
<?php
foreach($results as $row){
echo " <tr > <td> $row->participantID </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td></tr>";
}
?>
最佳答案
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);
}
型号:
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();
}
查看:
<?php foreach ($query as $row): ?>
<?php echo $row->answerA;?><br>
<?php endforeach; ?>
关于php - Codeigniter:两表查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28986857/