我在 CodeIgniter 中使用联接查询,但无法使其工作。它只显示一个表数据,而不显示另一表数据。我是 CodeIgniter 的新手,无法弄清楚这一点。请有人帮助我。提前Tnanks。
view
<?php foreach ($query as $row): ?>
<?php echo $row->answerA;?><br>
<?php echo $row->answerB;?><br>
<?php echo $row->answerC;?><br>
<?php echo $row->comment;?><br>
<?php echo $row->name; ?>
<?php endforeach; ?>
控制器
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('tblanswers.*,credentials.*');
$this->db->from('tblanswers');
$this->db->join('credentials', 'tblanswers.answerid = credentials.cid', 'right outer');
$query = $this->db->get();
return $query->result();
}
EDIT
的结果
print_r($data['query']);
die();
是一个数组,如下所示:
Array ( [0] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 83 [name] => Edvinas [second_name] => liutvaits [phone] => [email] => [email protected] ) [1] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 84 [name] => Edvinas [second_name] => liutvaits [phone] => [email] => [email protected] ) [2] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 85 [name] => Edvinas [second_name] => Liutvaitis [phone] => [email] => [email protected] ) [3] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 86 [name] => EdvinasQ [second_name] => LiutvaitisQ [phone] => 12345678 [email] => [email protected] ) [4] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 87 [name] => Edvinas [second_name] => Liutvaitis [phone] => 123456 [email] => [email protected] ) )
表结构
证书
cid(主要)、姓名、名字、电话、电子邮件
表格答案
答案ID(主),用户ID,问题,答案S,答案S,答案S。