我有一个表格,用户可以在其中选择书籍或美容单选按钮。代码在book上运行良好,但在beauty上显示错误。除了从数据库中获取的数据不同外,代码是相同的。我已经尝试过但仍然卡住了。错误 A PHP Error was encountered Severity: Notice Message: Undefined variable: beauty_detail Filename: controllers/Welcome.phpLine Number: 87 if($result == 0){ echo "no recommendation"; } else{ foreach($result as $key=>$value){ $q = $this->mymodel->fetchBeautydetail($key); foreach($q as $val){ $beauty_detail[$val->user_id]['product_id'] = $val->product_id; $beauty_detail[$val->user_id]['product_rating'] = $val->rating; } }(line number: 87) $this->load->view('beauty_dashboard', ['beauty_detail'=>$beauty_detail]); }
1 回答
守着一只汪
TA贡献1872条经验 获得超3个赞
问题是范围。
尝试以下。(beauty_detail
从 foreach 中声明)
$beauty_detail;
foreach($result as $key=>$value){
$q = $this->mymodel->fetchBeautydetail($key);
foreach($q as $val){
$beauty_detail[$val->user_id]['product_id'] = $val->product_id;
$beauty_detail[$val->user_id]['product_rating'] = $val->rating;
}
}
$this->load->view('beauty_dashboard', ['beauty_detail'=>$beauty_detail]);
}
- 1 回答
- 0 关注
- 117 浏览
添加回答
举报
0/150
提交
取消