PHP/MySQL why aren't these results being ordered?

Ian

New member
I'm trying to display the users in order by points. The code below is properly displaying users and points, but it won't place them in order of points. Can anyone tell me what I'm doing wrong? The code looks pretty clean to me.


foreach ($friends['data'] as $friend) {
$friendid = $friend['id'];
$result = mysql_query("SELECT * FROM users WHERE id='$friendid' ORDER BY points");

while($row = mysql_fetch_array($result))
{
echo $row['name'];
echo " " . $row['points'];
echo "<br />";
}
}

Again, the names and points are being properly pulled and displayed, but the "ORDER BY points" is not working correctly.
Ratchetr: The $friends array comes from the facebook's api, and it's returning more than one row. It's returning this...

Fake Userthree 2
Fake Usertwo 3
Fake User 0

Which is what it should be returning, except that it's not ordering them by the points. So I know that it's properly grabbing and displaying the data, everything works as it should except the "ORDER BY points"
Ratchetr: That's way over my head... I don't know how I can do that using the $friendid variable which I need in order to select the right ones, since they differ from person to person so I can't manually put them in.

This is what I have now...

foreach ($friends['data'] as $friend) {
$friendid = $friend['id'];
$result = mysql_query("SELECT * FROM users WHERE id IN ($friendid) ORDER BY points");

while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['points'];
echo "<br />";
}
}
 
Back
Top