MySQL in PHP can't get values that are equal
I'm trying to make a top users of my website, but the problem that I'm having is if one or more users have the same amount of won games only the first result appears on the website.
Im using this code to search in the database:
$rs1 = mysql_query(SELECT won,steamid,name,avatar,games
FROM `users`
WHERE won <> 0
GROUP BY won DESC LIMIT 18);
while($row = mysql_fetch_array($rs1))
{ //AND HTML CODE HERE...}
Can someone help me with this? I want to show all the users for example if they have the same number of won games, for example it would show like:
RANK - USER - WON
1 - NAME - 12
2 - NAME - 8
3 - NAME - 8
4 - NAME - 4
BTW I know that I should not usemysql_query
but I can't do it another way.
Answer
Solution:
I don't think you need the group by clause, but if you do, please consider using all the projection fields on group by. Although mysql allows you to group by different fields, it's not a good practice to do so.
Answer
Solution:
Seems to me that your
GROUP BY
should be anORDER BY
If that does not work please share the table structure
Answer
Solution:
Add name in to Group by clause