I am doing a friend list and it's not working very well. Well I tried to show all the user's friends but it's not working, it only shows one instead of all.
In MySQL friends_request table I have something like this:
(I don't know how to put a draw-able table here so i put the html of the table)
<table border="1">
<tr>
<td>id</td>
<td>from_username</td>
<td>to_username</td>
<td>requested</td>
<td>accepted</td>
</tr>
<tr>
<td>1</td>
<td>username1</td>
<td>username2</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>username1</td>
<td>username3</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>username2</td>
<td>username3</td>
<td>0</td>
<td>1</td>
</tr>
</table>
What it shows is just only one username instead all where username is the user logged in... For example, in 'username1' just appears as friends with 'username2' and not show as well with 'username3' I want to know why.
<?php
$selfriends = "SELECT * FROM friends_request WHERE from_username = '$user' OR to_username='$user' AND accepted = '1'";
$resultfriend = $sql->query($selfriends); // select the table of friends_request from database
$rowfriend = mysqli_fetch_assoc($resultfriend); // calls the string, char or number from friends_request table
$t1 = $rowfriend['from_username']; // calls user from_username from friends_request table
$t2 = $rowfriend['to_username']; // calls user to_username from friends_request table
$accepted = $rowfriend['accepted']; // calls accepted from friends_request table
$fid = $rowfriend['id'];
/* CHECK IF FRIEND GOT SOME PICTURE */
$selPicturePro = "SELECT * FROM users WHERE username = '$t1'";
$resultsPicPro = $sql->query($selPicturePro); // select the users table and find out the content of pic
$rowProfiles = mysqli_fetch_assoc($resultsPicPro); // calls the row of profile picture.
if($rowProfiles > 1) {
$profileView = "<img src='".$rowProfiles['profile']."' width='auto' height='155px' />";
} else {
$profileView = "<img src='images/no-picture.png' width='auto' height='100px' />";
}
$selPicturePro2 = "SELECT * FROM users WHERE username = '$t2'";
$resultsPicPro2 = $sql->query($selPicturePro2); // select the users table and find out the content of pic
$rowProfiles2 = mysqli_fetch_assoc($resultsPicPro2); // calls the row of profile picture.
if($rowProfiles2 > 1) {
$profileView2 = "<img src='".$rowProfiles2['profile']."' width='auto' height='155px' />";
} else {
$profileView2 = "<img src='images/no-picture.png' width='auto' height='100px' />";
}
if($user != $t1) { // if the user is not the sender and accepted = 1, then the
// receiver sees the other user.
echo '<h3>Friends</h3>';
echo '<a href="profile.php?u='.$t1.'" class="no-style">';
echo $profileView;.'<br />'.$t1;
echo '</a>';
}
else if($user != $t2) { // if the user is not the receiver and accepted = 1, then the
// sender see the other user.
echo '<h3>Friends</h3>';
echo '<a href="profile.php?u='.$t2.'" class="no-style">';
echo $profileView2.'<br />'.$t2;
echo '</a>';
}
if($user != $t1 && $accepted == 0) {
echo "<br clear='all' />";
echo "<h3>Friends</h3>";
echo "You don't have friends yet.";
}
if($user != $t2 && $accepted == 0) {
echo "<br clear='all' />";
echo "<h3>Friends</h3>";
echo "You don't have friends yet.";
}
?>