我正在尝试使用相关表构建我的数据库。但是,我从数据库中获得了正确的输出-由于用户是相同的,并且数据的唯一变化是课程,因此我想在同一行中收集值“Engelsk”和“Matematik”,而不是有两个几乎相同的输出,除了课程。如果不在数据库的同一行中,这甚至可能吗?如果是这样,我非常想知道如何:)
Array
(
[0] => Array
(
[Type] => Elev
[Username] => test
[Name] => Test Testsen
[Grade] => 9. Klasse
[Course] => Engelsk
)
[1] => Array
(
[Type] => Elev
[Username] => test
[Name] => Test Testsen
[Grade] => 9. Klasse
[Course] => Matematik
)
)
所以基本上我想要实现的是这样的:
Array
(
[0] => Array
(
[Type] => Elev
[Username] => test
[Name] => Test Testsen
[Grade] => 9. Klasse
[Course] => Engelsk, Matematik
)
我的查询如下所示:
SELECT
*
FROM
lek_Essentials
LEFT JOIN
lek_Type
ON
lek_Essentials.TypeId = lek_Type.TypeId
LEFT JOIN
lek_Grades
ON
lek_Essentials.GradeId = lek_Grades.GradeId
LEFT JOIN
lek_GradeCourses
ON
lek_Grades.GradeId = lek_GradeCourses.GradeId
LEFT JOIN
lek_Courses
ON
lek_GradeCourses.CourseId = lek_Courses.CourseId
LEFT JOIN
lek_Request
ON
lek_Courses.CourseId = lek_Request.CourseId
WHERE
lek_Essentials.UserId = lek_Request.UserId