<![CDATA[ Foreach xPDO result in html table - My Forums]]> https://forums.modx.com/thread/?thread=99295 <![CDATA[Foreach xPDO result in html table]]> https://forums.modx.com/thread/99295/getting-results-from-custom-table-with-xpdo#dis-post-536964
id | Name | useriD | bID | email


In row i have something like this

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]


When i try in phpmyadmin a simple query

SELECT COUNT(`Name`) AS `Requests`, `Name` AS `Names`
 FROM `table`
 GROUP BY `Names`
 ORDER BY `Requests` DESC
 LIMIT 5


I got proper results

Requests | Names
--------------------------
3 | John
3 | Michael
1 | Jovan
1 | Oliver
1 | Peter


But when i try something like this

$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);
 }
}


The problem is that i dont know how to display this in table?
]]>
miomir.dancevic Jan 13, 2016, 12:30 PM https://forums.modx.com/thread/99295/getting-results-from-custom-table-with-xpdo#dis-post-536964