我有一個(gè)表格,用戶可以在其中選擇書籍或美容單選按鈕。代碼在book上運(yùn)行良好,但在beauty上顯示錯(cuò)誤。除了從數(shù)據(jù)庫中獲取的數(shù)據(jù)不同外,代碼是相同的。我已經(jīng)嘗試過但仍然卡住了。錯(cuò)誤 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貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
問題是范圍。
嘗試以下。(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 關(guān)注
- 144 瀏覽
添加回答
舉報(bào)
0/150
提交
取消