We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11144
    • 10 Posts
    How would I do the following in xPDO?

    SELECT categories, COUNT(*) AS cat_count FROM Box GROUP BY categories;
    


    Here is what I have so far:

    $query = $xpdo->newQuery('Box');
    $query->select('id, category');
    $query->groupBy('category');
    $boxes = $xpdo->getCollection('Box',$query);  
    
    foreach ($boxes as $row) {
    $rows .= $row->get('category').$row->get('cat_count').'<br />';
    }
    
    echo $rows;
    


    Tried adding COUNT(*) AS cat_count to the ->select but it doesn’t seem to work. Any ideas?