Php MySQL表连接取决于条件
我有四张这样的桌子: 表1:考试Php MySQL表连接取决于条件,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有四张这样的桌子: 表1:考试 -----------+--------------+--------- examID | examName | session | -----------+--------------+--------- 表2:课程 -----------+--------------+--------- courseID | title | credit | -----------+--------------+--------- 表
-----------+--------------+---------
examID | examName | session |
-----------+--------------+---------
表2:课程
-----------+--------------+---------
courseID | title | credit |
-----------+--------------+---------
表3:审查员
-------------+----------+-------------+------------+--------+
examinerID | examID | teacherID | courseID | part |
-------------+----------+-------------+------------+--------+
1 | 1 | 3 | 5 | A or B |
-------------+----------+-------------+------------+--------+
表4:标记
---------+--------------+-------------+-----------+------
markID | examinerID | studentID | courseID | mark |
---------+--------------+-------------+-----------+------
我想在这些表上运行一些查询,以便根据examID生成课程表单考官表的php数组,如下所示:-
$marks['courseID'] = array(
'course' => array(),//array of course details
'part_a_mark'=> array(),// array of marks of part A of that courseID
'part_B_mark'=> array(),// array of marks of part B of that courseID
);
使用SQL语句无法直接获得预期的输出。您需要在php循环语句中处理查询结果,然后通过遍历结果形成数组。没有SQL语句会为您提供php数组。