我有这个league_table:
+--------+----------+-------------+
| id | star | section |
+--------+----------+-------------+
| 1 | 1 | A |
| 2 | 0 | A |
| 3 | 1 | B |
| 4 | 1 | B |
| 5 | 0 | C |
| 6 | 1 | C |
| 7 | 0 | D |
| 8 | 1 | D |
+--------+----------+-------------+我想知道这是否可能,我可以得到他们在团队中返回的回报吗?
说如果我做了这个简单的查询SELECT id, star FROM league_table WHERE star = 1",然后使用PDO FETCH ALL
我可以有这个输出:
Array
(
[0] => Array
(
[id] => 1
[star] => 1
)
[1] => Array
(
[id] => 3
[star] => 1
)
[2] => Array
(
[id] => 4
[star] => 1
)
[3] => Array
(
[id] => 6
[star] => 1
)
[4] => Array
(
[id] => 8
[star] => 1
)
)但是,我可以有这个输出,以便它更有组织?
Array
(
[A] => Array
(
[0] => Array
(
[id] => 1
[star] => 1
)
)
[B] => Array
(
[0] => Array
(
[id] => 3
[star] => 1
)
[1] => Array
(
[id] => 4
[star] => 1
)
[C] => Array
(
[0] => Array
(
[id] => 6
[star] => 1
)
)
[D] => Array
(
[0] => Array
(
[id] => 8
[star] => 1
)
)
)