Hey guys, 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 I have something like this:

username1 -> username2
username1 -> username3
username2 -> username3

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.

here i left the quote of selecting the friends from the friends.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.
            ?> <h3>Friends</h3> <a href="profile.php?u=<?php echo $t1; ?>" class="no-style"> <?php echo $profileView; ?><br /> <?php echo $t1; ?> </a> <?php
                }
                else if($user != $t2) {                                         // if the user is not the receiver and accepted = 1, then the    
                                                                                                // sender see the other user.
            ?> <h3>Friends</h3> <a href="profile.php?u=<?php echo $t2; ?>" class="no-style"> <?php echo $profileView2; ?><br /> <?php echo $t2; ?> </a> <?php
                }
                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.";
                }           

            ?> 
Member Avatar for diafol

If you want to display multiple records, you need to use a loop, usually a "while".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.