按枚举分组到数组PHP
我有一些sql表按枚举分组到数组PHP,php,mysql,Php,Mysql,我有一些sql表 +----+------+--------+------------+------------+ | id | code | name | Instructor | PlanePilot | +----+------+--------+------------+------------+ | 1 | 001 | sasha | N | N | | 2 | 002 | sasha2 | Y | N
+----+------+--------+------------+------------+
| id | code | name | Instructor | PlanePilot |
+----+------+--------+------------+------------+
| 1 | 001 | sasha | N | N |
| 2 | 002 | sasha2 | Y | N |
| 3 | 003 | sasha3 | N | Y |
| 4 | 004 | sasha4 | Y | Y |
| 5 | 005 | sasha5 | Y | Y |
| 6 | 006 | sasha6 | N | N |
| 7 | 007 | sasha7 | Y | N |
| 8 | 008 | sasha8 | Y | N |
+----+------+--------+------------+------------+
我想按讲师PlanePilot分组将所有内容排序到PHP数组中
我想得到一些php数组,如:
$array =[
withoutInstructorPLANEPilot:[sasha,sasha6],
Instructor:[sasha2,sasha4,sasha5,sasha7,sasha8],
PlanePilot:[sasha3,sasha4,sasha5]
]
如果没有3个select查询(如:
SELECT * FROM mytable where Instructor= 'Y'
我想用1个查询将其转换为PHP数组这是您想要的吗
select group_concat( (case when Instructor = 'N' and PlanePilot = 'N' then name end) ) as neither,
group_concat( (case when Instructor = 'Y' then name end) ) as instructors,
group_concat( (case when PlanePilot = 'Y' then name end) ) as planepilots
from t;
编辑你的问题并显示你想要得到的结果。好的,请稍等。你可以在获取表格后在PHP循环中完成这项工作。