【发布时间】:2014-04-05 06:48:25
【问题描述】:
我正在使用 mysqli 从数据库中获取数据并将其放入带有 while 循环的数组中。当我回显数组时,我得到一个空数组,但是在一个函数中,我之前确实执行过此代码,但它与数据库的结果不同。我知道数据库提供了良好的数据,因为当我回显结果 $idGroup 它给我 2 这是正确的。
Ps 我知道它会不断替换自己,因为我没有指定索引 私有函数组() { $函数运行 = 0; $i = 0; $helperArray = 数组(); $this->grouplist = array();
$query = "SELECT GroupName, Groups.idGroup
FROM Groups
INNER JOIN Members
ON Groups.idGroup = Members.idGroup
WHERE Members.idMember = ? ";
//prepare query and execute
if($stmt = $this->connection->prepare($query))
{
$stmt->bind_param('s', $this->id);
$stmt->execute();
$stmt->bind_result($GroupName, $idGroup);
while ($stmt->fetch())
{
$helperArray[] = $idGroup;
}
echo $helperArray;
}
【问题讨论】:
-
你应该在 $helperArray 上使用 print_r,而不是 echo
-
wow easy fix 应该知道谢谢