我刚开始使用 Codeigniter,这让我抓狂。我有一个查询来确定用户是否购买了任何程序。然后,我必须使用该程序的类型类别来运行并确定他或她在另一个表中记录了多少次查询。很抱歉造成混乱,但希望代码有意义。
我在将两个数组从我的模型返回到我的控制器到视图中时遇到问题。
function specificPrograms() {
$specific_sql = $this->db->query("SELECT program,created FROM `assessment` WHERE uid = $this->uid");
if($specific_sql->num_rows() > 0) {
foreach ($specific_sql->result() as $specific) {
$data[] = $specific;
$this->type = $specific->program;
}
return $data;
}
$sub_sql = $this->db->query("SELECT id FROM othertable WHERE user_id_fk = $this->uid and type = '$this->type'");
if($sub_sql->num_rows() > 0) {
foreach ($sub_sql->result() as $otherp) {
$data[] = $otherp;
}
return $data;
}
}
然后在我的控制器中,
$data['specific'] = $this->user_model->specificPrograms();
$data['otherp'] = $this->user_model->specificPrograms();
谢谢你的帮助。