PDO显示GROUPED BY的项目

时间:2018-05-13 13:31:06

标签: php mysql mysqli pdo

我正在尝试显示包含ItemCount的组(GroupNo)的所有项目(TicketNo)。问题是:它只显示第一个项目。这是我的代码:

<?php 
foreach($dbh->query('SELECT GroupNo,COUNT(*),Tickets.* 
                    FROM Tickets 
                    WHERE entryScans != 0 
                    GROUP BY GroupNo') as $row) {
    echo "<tr><th>" . $row['GroupNo'] . "</th><th>" . $row['COUNT(*)'] . "</th></tr>";
    echo "<tr><th>" . $row['TicketNo'] . "</th><th>" . $row['hash'] . "</th></tr>";
}
               ?>

编辑: 这是我想要的结果:

Gourp 1 (Count:3)
- Ticket 1
- Ticket 2
- Ticket 3
Group 2 (Count:2)
- Ticket 4
- Ticket 5
Group 3 (Count:4)
- Ticket 6
- Ticket 7
- Ticket 8
- Ticket 9

但我现在得到的是:

Gourp 1 (Count:3)
- Ticket 1
Group 2 (Count:2)
- Ticket 4
Group 3 (Count:4)
- Ticket 6

0 个答案:

没有答案