Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按枚举分组到数组PHP_Php_Mysql - Fatal编程技术网

按枚举分组到数组PHP

按枚举分组到数组PHP,php,mysql,Php,Mysql,我有一些sql表 +----+------+--------+------------+------------+ | id | code | name | Instructor | PlanePilot | +----+------+--------+------------+------------+ | 1 | 001 | sasha | N | N | | 2 | 002 | sasha2 | Y | N

我有一些sql表

+----+------+--------+------------+------------+
| 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循环中完成这项工作。