9阅网

您现在的位置是:首页 > 知识 > 正文

知识

php - 讯息。在CODEIGNITER中未定义变量:beauty_detail [重复] 。

admin2022-11-07知识18
这个问题在这里已经有了答案: "通知。"通知:未定义的变量"、"通知:未定义的索引"、"通知:未定义的指数"。Undefined index", "Notice: Undefined index", and "Notice: 未定义偏移",使用PHP (28个答案) 封闭 上月.

我有一个表单,用户可以选择 书籍美人 单选按钮。代码工作正常 书籍 但显示错误的 美人. 代码是一样的,只是从数据库中获取的数据不同。我试过了,但还是卡住了。

ERRORA 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]);
        }


【回答】:

问题是 范围.

试如下。(声明 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]);
        }