CodeIgniter连接两个表 [英] CodeIgniter join two tables

查看:118
本文介绍了CodeIgniter连接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用CodeIgniter连接两个表。我使用CodeIgniter用户指南寻求帮助。我有一些问题,其中只有一个表的数据显示,我不知道为什么。

I am trying to join two tables together using CodeIgniter. I used CodeIgniter user guide for help. I am having some issues where only one table's data is displayed and I don't know why. Can someone help me out?

以下是我的代码:

控制器 / p>

Controller

function getall(){      
    $this->load->model('result_model');
    $data['query'] =
    $this->result_model->result_getall();
    $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();

    }

查看

View

    <div>    


 <?php foreach ($query as $row): ?>      
                     //tblanswers
                   <?php echo $row->answerA;?><br>
               <?php echo $row->answerB;?><br>
               <?php echo $row->answerC;?><br>
                   <?php echo $row->comment;?><br>
                  //credentials
                    <?php echo $row->name; ?>
         <?php endforeach; ?>  


   </div>


推荐答案

在控制器中试试,看看结果。 ,请告诉我们您是否收到任何错误,并确保表格中有数据)。

Try this in controller and see whats the result.Also,show us if you are getting any error and make sure there is data in your table :).

控制器

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

这篇关于CodeIgniter连接两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆