douqun1977 2016-10-15 06:26
浏览 67

使用PHP在Codeigniter中连接两个表

I am trying to join two tables and return an array in my Model method in CodeIgniter with php. I've gone through a few previously posted similar questions on stackoverflow and modified my code accordingly. But they don't seem to work. Hence would love to know what's wrong with the following.

I'm using the following method but am currently getting exceptions. Would appreciate suggestions in this regard.

Model Method

public function getUserDetails($username)
{
    $uid = $this->getUserUid($username);
    $this->db->select('s.uid, s.name,s.phone, s.studentId, s.type, sp.profiledesc, sp.age');
    $this->db->from('sysuser as s');
    $this->db->join('studentprofile as sp', 's.uid = sp.uid', 'left');
    $this->db->where(array('s.uid' => $uid));
    $query = $this->db->get();
    return $query->result();
}

Controller

$data1['details'] = $this->userModel->getUserDetails($username);
$this->load->view('studentDashboard/viewProfile',$data1);

View

...
<h2>
   <?php foreach($details as $detail){?>
        <?php echo $detail->s.name;?>
   <?php }?>
</h2>
...

In the view, I've also tried just echoing $detail->name but this doesn't work either.

  • 写回答

3条回答 默认 最新

  • dpecb06062 2016-10-15 06:32
    关注
    1. At first, use print_r($details) for checking your data. If it's returning anything or not.

    2. Then echo your value like this $detail['name']

    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真