php无法获取已有数据,php – 无法在codeigniter中从模型获取整个数据值

我有3张桌子

学生

id s_name

1 S1

2 S2

student_subject

id s_id subject

1 1 english

2 1 science

3 2 mathematics

4 2 poetry

老师

id t_id s_id

1 1 1

2 1 2

我正在尝试为老师制作一个仪表板,在那里他可以看到他下面的所有学生以及学生正在关注的科目.

我有老师的id(在t_id中)在控制器中,然后在模型中,从那里我从教师表中获取学生的ID(作为$s_id)并通过这个s_id我希望得到来自student table和student_subject表的详细信息.

我面临的问题是

1) In the model i am able to see all the details of student table but when i return the value to controller and then to view i get the detail of only 1 student.

2) In this model along with the student details i also wish to return the subjects that are under a particular student from student_subject table,however i don’t know how to return 2 values(i.e student details and subject details) from 1 model to 1 controller and then to view

我关注的代码是

调节器

public function dashboard($t_id)

{

$data['student_request'] = $this->student_model->student_detail($t_id);

$this->load->view('teacher/dashboard_view',$data);

}

模型

public function student_detail($t_id)

{

$query = $this->db->query("SELECT * FROM teacher where t_id = $t_id");

foreach ($query->result_array() as $row)

{

$s_id = $row['s_id'];

$new_query = $this->db->query("SELECT * FROM student where id = $s_id");

$s = $new_query->result_array();

//print_r ($s); // just to check the data

return $s;

}

}

视图

PHP

foreach ($student_request as $row)

{

echo $row['s_name'];

}

?>

如果有人能帮我解决这个问题,我真的很感激

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值