This question already has an answer here:
$sql = "SELECT * FROM groups WHERE id IN (SELECT group FROM groupmembers WHERE user = $my_userid)";
Okay so the structure of groups
looks like this: name, id, privacy
and the structure of groupmembers looks like this: group, user
The variable $my_userid
has already been defined and has the value of 1.
I'm trying to execute the sql above and then include a file which will echo the group name, i've added myself to 2 groups so i should echo test1 and test2, the included file works, i've tried including it twice just to see if there was any problem with it and it wasn't. I cannot see what's wrong, i've looked for a fix here but haven't found it. The whole php code is below:
<?php
$sql = "SELECT * FROM groups WHERE id IN (SELECT group FROM groupmembers WHERE user = $my_userid)";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$g_name = $row['name'];
$g_id = $row['id'];
include 'files/social/group.php';
}
} else {
// Nothing to display, user is not in any group.
}
?>
</div>