我在codeigniter中使用連接函數並且無法讓它工作它只顯示一個表數據但不是其他新的codeigniter無法找出這個請求有人幫我提前tnx。在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();
}
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(PRIMARY),名稱,秒ond_name,電話,電子郵件
tblanswers
answerid(主),用戶ID,questionid,answerA,answerB,answerC。
訪問頁面roytuts.com/codeigniter-join-example/ – user3470953 2016-05-28 03:41:42