MstrGmrDLP Posted April 10, 2014 Share Posted April 10, 2014 Requesting help from anyone who is a geek. My code is checking all of the friends where the logged in user is user_id. It gets all of the values but only displays 1. What am I doing wrong? Code $friend = mysql_query("SELECT * FROM friends WHERE user_id={$_SESSION['user']['user_id']}");$row = mysql_fetch_assoc($friend);$friends = mysql_query("SELECT user_name, user_pic, user_id FROM users WHERE user_id={$row['friend_user_id']}"); Then later on I have a while loop getting this information. But it only displays 1 users information. Why won't it show them all? If you could help I would be really happy Quote Link to comment https://forums.phpfreaks.com/topic/287660-mysql_fetch_assoc-only-returning-1-value-instead-of-all-of-them/ Share on other sites More sharing options...
Solution requinix Posted April 10, 2014 Solution Share Posted April 10, 2014 Because you only got one row. If you want all of them then you need to put the mysql_fetch_assoc() stuff into its own while loop. But that's not very efficient. You could just execute one query to get all the user information for all the friends. SELECT users.user_name, users.user_pic, users.user_id FROM users JOIN friends ON users.user_id = friends.friend_user_id WHERE friends.user_id = that id you have in the sessionOne while loop. Quote Link to comment https://forums.phpfreaks.com/topic/287660-mysql_fetch_assoc-only-returning-1-value-instead-of-all-of-them/#findComment-1475622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.