[英]Return array pulled from MySQL using PHP
I am trying to pull all badges associated to a particular user that is logged into my site. 我试图提取与登录到我的网站的特定用户相关的所有徽章。 On my index.php page I have,
在我的index.php页面上,
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
print_r(get_badges($_SESSION['user_id'], $mysqli));
?>
My db_connect.php: 我的db_connect.php:
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
and on my functions.php I have, 在我的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;
}
?>
The problem is that the piece in the functions.php page makes my page go blank. 问题是在functions.php页面中的内容使我的页面空白。 When I remove it, the page looks normal.
当我删除它时,页面看起来正常。 What am I doing wrong?
我究竟做错了什么?
You have syntax error in your code . 您的代码中有语法错误。 change
更改
$badges[] = $row["badgeId"]);
to 至
$badges[] = $row["badgeId"];
and also change 并且也改变
$badges[] = array();
to $badges = array();
到
$badges = array();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.