On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I am having problems with query in xPDO i have some custom table like this

    id | Name | useriD | bID | email


    In row i have something like this

    1 | Michael | 34 | 45 | email@email.com
    2 | Michael | 34 | 45 | email@email.com
    3 | John    | 34 | 45 | email@email.com
    4 | John    | 34 | 45 | email@email.com
    5 | John    | 34 | 45 | email@email.com
    6 | Jovan   | 34 | 45 | email@email.com
    7 | Peter   | 34 | 45 | email@email.com
    8 | Michael | 34 | 45 | email@email.com
    9 | Oliver  | 34 | 45 | email@email.com
    10 | Tataian | 34 | 45 | email@email.com


    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?
    [ed. note: miomir.dancevic last edited this post 4 years, 6 months ago.]
      <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>