消息:未定义变量:CODEIGNITER 中的 beauty_detail
Message: Undefined variable: beauty_detail in CODEIGNITER
我有一个表单,用户可以在其中 select book 或 beauty 单选按钮。代码在 book 上运行良好,但在 beauty 上显示错误。除了从数据库中获取的数据不同外,代码是相同的。我试过了,但还是卡住了。
错误
A PHP Error was encountered Severity: Notice
Message: Undefined variable: beauty_detail
Filename: controllers/Welcome.php
Line 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]);
}
问题是 scope。
试试看。 (从 foreach 中声明 beauty_detail
)
$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]);
}
我有一个表单,用户可以在其中 select book 或 beauty 单选按钮。代码在 book 上运行良好,但在 beauty 上显示错误。除了从数据库中获取的数据不同外,代码是相同的。我试过了,但还是卡住了。
错误
A PHP Error was encountered Severity: Notice
Message: Undefined variable: beauty_detail
Filename: controllers/Welcome.php
Line 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]);
}
问题是 scope。
试试看。 (从 foreach 中声明 beauty_detail
)
$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]);
}