Forum Moderators: open
Since a lot of users have more than 20 friends, right now this is whats happening:
1) Loop through all your friends.
2) On each loop, it commits another query that gets the count of friends.
So, if I (user id 1) have 20 friends, there will be 21 sql queries... something like:
SELECT id_friend FROM friends WHERE id_user=1
SELECT COUNT(id_friend) AS q FROM friends WHERE id_user=X
where X is the current loop of the previous' query's id_friend.
Is there any way to join them together? (having 1 query instead of 21).