I have 2 tables
usrfrnd_table
user_id friend_id
__________________
1 1
2 5
3 1
2 1
and usr_table
id fullname
________________
1 John Doe
2 George Cann
...
How to echo all friends of for example id 2 from table usr_table with loop?
Tried this piece of code. but doesn’t work
$stmt = "SELECT fullname FROM usr_table INNER JOIN usrfrnd_table ON usr_table.id=usrfrnd_table.friend_id WHERE usrfrnd_table.user_id='$id'";
$result=$db->query($stmt);
foreach($result as $rec){
echo "<li><a href=user.php?id=".$rec['id']."'>". $rec['fullname'] . "</a></li>";
}
Try this: