我打印出表格中的信息(tblgroups)。之后我想打印出来自团队成员的头像(来自tblusers)(tblgroup_member)
当我尝试将group_id(从我打印出来的组中)推送到Getmembers函数时,它告诉我我在非对象上调用函数( $memberinfo = $group->Getmembers($group["group_id"]);
)。但我宣布$group = new Group();
?
它告诉我错误在这一行:$memberinfo = $group->Getmembers($group["group_id"]);
PHP
$group = new Group();
foreach ($groups as $group) {
echo "<p class='groupname'><a href='group.php?group_id=" . $group['group_id']. "'>" . $group['group_name'] . "</a></p>";
echo $group['group_id'];
$memberinfo = $group->Getmembers($group["group_id"]);
/*
foreach ($memberinfo as $member)
{
echo "<p>" . $member['avatar'] . "</p>";
}
*/
}
FUNCTION GETMEMBERS(如有必要)
public function Getmembers($group_id) {
$db = new Db();
$select = "SELECT
g.group_id,
m.user_id,
u.avatar
FROM ((tblgroups g INNER JOIN tblgroup_member m ON g.group__id = m.group__id) INNER JOIN tblusers u ON u.user_id = m.user_id)
WHERE g.group_id = " . $group_id . " ";
$result = $db -> conn -> query($select);
$result_array=array();
while ($row = mysqli_fetch_array($result)) {
$result_array[]=$row;
}
return $result_array;
}
答案 0 :(得分:0)
你有第一件事
$group = new Group();
然后循环
foreach ($groups as $group) {
你正在使用的循环
$memberinfo = $group->Getmembers($group["group_id"]);
此处$group->
并不意味着该对象是来自foreach
的数组数据。或者换句话说,它被覆盖并且$group
不再是一个对象
<强>解决方案强>
更改
$group = new Group();
到
$group_obj = new Group();
然后
$memberinfo = $group->Getmembers($group["group_id"]);
到
$memberinfo = $group_obj->Getmembers($group["group_id"]);