在我的应用程序中,我试图从不同组的用户那里获取信息。
在group.php上,我概述了所有组。目前我只打印出群组名称,但我也希望打印出这样的成员头像:
来自会员的4个头像|组名
功能:
public function GetAllYourGroups($user_id) {
$db = new Db();
$select = "SELECT * FROM tblgroup_member WHERE user_id = $user_id";
$result = $db -> conn -> query($select);
$result_array=array();
while ($row = mysqli_fetch_array($result)) {
$result_array[]=$row;
}
return $result_array;
}
PHP:
$group = new Group();
$user = new User();
$groups= $group->GetAllYourGroups($user_id);
$user_id = $user -> getUserByEmail($email);
foreach ($groups as $group) {
echo "<p class='groupname'><a href='group.php?group_id=" . $group['group_id']. "'>" . $group['group_name'] . "</a></p>";
}
使用新功能我试图获得具有2个内部联接的头像,但我不知道如何获得我在上一个函数中打印出的group_id。
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;
}
以下是我使用的表格:
tblgroups - group_id
tblgroup_member: - group_id - User_id
向tblUsers - 用户身份 - 头像