$sql = "SELECT
u.username,
count(*) as count
FROM
offersdone o
LEFT JOIN
users u
ON u.ID = o.uid
GROUP BY
o.uid
ORDER BY
count(*) DESC";
$getlast = mysql_query($sql);
$content .= "<table><tr><th>Username</th><th>Total Offers</th></tr>";
while($last = mysql_fetch_array($getlast)){
$content .= "<tr><td>" . $last['username'] . " </td><td> " . $last['count'] . "</td></tr>";
}
При этом следует выбрать имя пользователя и количество предложений с одним запросом, которые уже отсортированы по количеству предложений.
Демо:
mysql> SELECT * FROM offersdone;
+-----+
| uid |
+-----+
| 1 |
| 1 |
| 2 |
| 2 |
| 2 |
| 2 |
+-----+
6 rows in set (0.00 sec)
mysql> SELECT * FROM users;
+----+----------+
| ID | username |
+----+----------+
| 1 | A |
| 2 | B |
+----+----------+
2 rows in set (0.00 sec)
mysql> SELECT u.username, COUNT( * ) as count
-> FROM offersdone o
-> LEFT JOIN users u ON u.ID = o.uid
-> GROUP BY o.uid
-> ORDER BY COUNT( * ) DESC;
+----------+-------+
| username | count |
+----------+-------+
| B | 4 |
| A | 2 |
+----------+-------+
2 rows in set (0.00 sec)