[英]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. 我想查看临床表中而不是实验室表中的PID。
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>";
}
?>
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; ?>
The problem lies in your model. 问题出在您的模型上。 You are not returning the proper array results.
您没有返回正确的数组结果。 You have to first use
get()
to build the query and place it into a variable like $q
, then use that variable with a the result()
method to obtain the results, like this : 您必须首先使用
get()
构建查询并将其放入$q
类的变量中,然后将该变量与result()
方法一起使用以获取结果,如下所示:
$q = $this->db->get();
return $q->result();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.