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 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用