SELECT p.userID, p.name, p.age, f.userid AS fuserid, f.name AS fname, f.age AS fage
FROM members p
LEFT JOIN friendships fs ON (p.userID = fs.userID)
INNER JOIN members f ON (fs.friendID = f.userID)
WHERE p.userid = $_SESSION['userID'] AND fs.accepted = 1
You're second post structure and field combinations do not match what you're original definition is. I added the userid condition assuming that userID is still correct, and the accepted assuming its a part of friendships.
1) Don't use SELECT *, actually name the columns you need. Your queries will be much clearer down the road because of it
2) when giving an alias name the AS word is optional so yourtable AS yt or yourtable yt are interchangeable
3) an INNER JOIN matches rows in both tables. a LEFT OUTER JOIN returns all rows from the first table and matching rows from the right table, plus null rows where there are no matches.
If you have a list of all students in a class and want to see what marks they got on a test you can use an INNER JOIN for the two tables. But if Johnny was away for that test he won't be returned in the list of results if you use an INNER JOIN because there is no row for him in the marks table. if you want to see all students and their marks or the fact that they are missing a mark on the test, then use a LEFT OUTER JOIN with the student table first. So Johnny's row will show up but you will see a NULL next to his test score.
There are other joins but you won't run into them as often. You can read up on CROSS JOIN, FULL JOIN (which mysql doesn't support) among others. Note that RIGHT OUTER JOIN is the same as a LEFT OUTER JOIN but all the rows from the right hand table are returned. Choose one of LEFT or RIGHT and don't mix the two as it is difficult to figure out why some rows are being returned and not others when you do so. I read left to right so choose to use a LEFT JOIN myself. Note that OUTER is an optional word but using it is helpful to remind you it is an outer join.
I decided i was gonna show unaccepted users, after a bit of tweaking your code Fou-lu worked, this is what I used
SELECT p.user_id, p.username, f.user_id AS fuserid, f.username AS fname, fs.accepted
FROM members p
LEFT JOIN friendships fs ON (p.user_id = fs.userID)
INNER JOIN members f ON (fs.friendID = f.user_id)
WHERE p.user_id = ".$_SESSION['userID']."
At first it kept echoing my username until i realised i needed to echo fname not username :P