我试图提取与登录到我的网站的特定用户相关的所有徽章。在我的index.php页面上,

<?php
     include_once 'includes/db_connect.php';
     include_once 'includes/functions.php';
     print_r(get_badges($_SESSION['user_id'], $mysqli));
?>


我的db_connect.php:

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);


在我的functions.php上,

<?php
function get_badges($u, $mysqli){
     $badges[] = array();

     if ($mysqli->connect_errno) {
        printf("Connect failed: %s\n", $mysqli->connect_error);
        exit();
    }

    $query = "SELECT * FROM memBadges WHERE ownerId = $u";

    if ($result = $mysqli->query($query)) {

        while ($row = $result->fetch_assoc()) {
            $badges[] = $row["badgeId"]);
        }
    }

$mysqli->close();

return $badges;
}
?>


问题是在functions.php页面中的内容使我的页面空白。当我删除它时,页面看起来正常。我究竟做错了什么?

最佳答案

您的代码中有语法错误。更改

$badges[] = $row["badgeId"]);




$badges[] = $row["badgeId"];


并且也改变

$badges[] = array();$badges = array();

10-05 20:27