Reputation: 11
Ok on my website it displays the users friends but it doesn't have their profile picture?
I have 2 databases. One is Users and that is were i save all the users details. the second database has if they are friends in it?
My question is how to get their profile pic from the users table .
p.s. the profile pic row is Proimg
this is my code
Tables
In the 2nd database i have the friends details id Sender Receiver Accepted 1 bob bill 1 2 fred bill 3
Accepted:
1 means that they havent accepted or declined 2 means that they have accepted 3 means that they have declined
In the 1st table i have the users details...
id Fullname Password proimg birthday 1 bill **** hi.jpg 1991-01-01 2 bob **** hello.jpg 1991-07-02 3 fred **** hey.jpg 1991-10-05 <?php $term = $fullname; $sql12 = mysql_query("select * from Friends where Reciver like '%$term%' or Sender like '%$term%'"); $Friends = mysql_num_rows($sql12); $t=1; while($t<=$Friends) { while ($row = mysql_fetch_array($sql12)) { If ($row['accepted'] == 2) { Echo '<img src="images/defaultprof.png" width="45px" height="45px"/>'; } else { $_SERVER['PHP_SELF']; } } $t++; } ?>
Upvotes: 0
Views: 81
Reputation: 14941
You'd probably want to INNER JOIN
the user data of the friends. This could be done like this: (based on made up tables ofcourse).
SELECT f.*, u.proImg FROM friends AS f
INNER JOIN users AS u ON u.userID = f.friendID
WHERE f.userID = 1;
Read entire JOIN
syntax here.
Upvotes: 3