id | Name | useriD | bID | email
1 | Michael | 34 | 45 | [email protected] 2 | Michael | 34 | 45 | [email protected] 3 | John | 34 | 45 | [email protected] 4 | John | 34 | 45 | [email protected] 5 | John | 34 | 45 | [email protected] 6 | Jovan | 34 | 45 | [email protected] 7 | Peter | 34 | 45 | [email protected] 8 | Michael | 34 | 45 | [email protected] 9 | Oliver | 34 | 45 | [email protected] 10 | Tataian | 34 | 45 | [email protected]
SELECT COUNT(`Name`) AS `Requests`, `Name` AS `Names` FROM `table` GROUP BY `Names` ORDER BY `Requests` DESC LIMIT 5
$result = $modx->query("SELECT COUNT(`Name`) AS `Requests`, `Name` AS `Names` FROM `table` GROUP BY `Names` ORDER BY `Requests` DESC LIMIT 5"); if (!is_object($result)) { return 'No result!'; } else { while($row = $result->fetch(PDO::FETCH_ASSOC)) { print_r($row); } }