php - $ROW = 未定义?

标签 php html mysql mysqli

我得到了

"Undefined variable: row" for the following code at the " return ($row);"

$ROW 不是定义在 $ROW[] = Array(...) 吗?

 <?php
    function fetchImageState(){
        $state = $_GET['state'];
        global $mysqli,$db_table_prefix;
        $stmt = $mysqli->prepare("SELECT athletedetails.UserID,
    	athletedetails.State_Code,
    	filesrepository.user_id,
    	filesrepository.new_file_name,
    	filesrepository.file_ID
    FROM athletedetails INNER JOIN filesrepository ON athletedetails.UserID = filesrepository.user_id
    WHERE athletedetails.State_Code = '$state'
      ");
        $stmt->execute();
        $stmt->bind_result($UserID, $statecode, $user, $file_id, $new_file_name);
        while ($stmt->fetch()){
            $row[] = array(
                'userID' => $UserID,
                'state' => $statecode,
                'user' => $user,
                'fileid' => $file_id,
                'newfilename' => $new_file_name);
        }
        $stmt->close();
        return ($row);
    }
?>

最佳答案

$row需要在while语句之前定义。目前只存在于while语句范围内,返回前销毁。

注意 $row 可能不包含您期望返回的值。但我也不经常使用 PHP,但可能会。

关于php - $ROW = 未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34246930/

相关文章:

php - SQL 中的连接数

php - 使用 PHP 在数据库中实现值检查的最佳方法

html - 显示 css 属性不适用于打印样式表

php - 使用 php 和 mysql 的简单 html 表单。如何维护数据库中空字段的 NULL 值

php - 在 php 中连接到 MySQL 数据库时遇到问题

javascript - 如何在保持可维护性的同时分离关注点(JS、HTML)?

mysql - 如何统计多个表的行数

mysql - 药店数据库设计建议

html - 如何完全切断因溢出 :hidden 部分隐藏的未知高度的列表元素

javascript - JQuery 移动对话框错误 SecurityError : The operation is insecure