gpt4 book ai didi

php - 在 CodeIgniter 中加入查询

转载 作者:可可西里 更新时间:2023-11-01 13:39:06 24 4
gpt4 key购买 nike

<分区>

我在 CodeIgniter 中使用连接查询,但无法正常工作。它只显示一个表数据,不显示另一个。我是 CodeIgniter 的新手,无法弄清楚这一点。请有人帮助我。提前告知。

查看

<?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);

}

模型

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();

}

编辑

结果

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] => ledvinas@yahoo.ie ) [1] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 84 [name] => Edvinas [second_name] => liutvaits [phone] => [email] => ledvinas@yahoo.ie ) [2] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 85 [name] => Edvinas [second_name] => Liutvaitis [phone] => [email] => ledvinas@yahoo.ie ) [3] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 86 [name] => EdvinasQ [second_name] => LiutvaitisQ [phone] => 12345678 [email] => ledvinas@yahoo.ie ) [4] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 87 [name] => Edvinas [second_name] => Liutvaitis [phone] => 123456 [email] => ledvinas@yahoo.ie ) ) 

表结构

证书

cid(PRIMARY), name, second_name, phone, email

回答

answerid(PRIMARY), userid, questionid, answerA, answerB, answerC.

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com