后通过PHP组或人造黄油SQL行有一个MySQL表像波纹管我如何查询
id | roll | exam_id | course_id | marks | status
----------------------------------------------------------
1 | 01001 | 1 | 1 | 56 | 1
2 | 01002 | 1 | 1 | 68 | 1
3 | 01003 | 1 | 1 | 55 | 1
4 | 01004 | 1 | 1 | 67 | 1
5 | 01001 | 1 | 2 | 54 | 1
6 | 01002 | 1 | 2 | 59 | 1
7 | 01003 | 1 | 2 | 62 | 1
8 | 01004 | 1 | 2 | 63 | 1
9 | 01001 | 2 | 3 | 61 | 1
10 | 01002 | 2 | 3 | 48 | 1
11 | 01003 | 2 | 3 | 22 | 1
12 | 01004 | 2 | 3 | 39 | 1
现在我想将所有的行与exam_id = 1
SELECT * FROM result WHERE exam_id=1 ORDER BY course_id
之后,我需要在将其分组为roll
后,将该表格显示在HTML内部表示按照结果表的行程编号具有行跨距的一行
Roll | course_id | marks
-----------------------------
01001 | 1 | 56
| 2 | 68
-----------------------------
01002 | 1 | 55
| 2 | 67
-----------------------------
01003 | 1 | 55
| 2 | 62
-----------------------------
01004 | 1 | 67
| 2 | 63
我正在使用Codeigniter框架来做这个项目。有关我如何才能做到这一点的任何建议?
预先感谢您。
[编辑] 当前SQL我使用这样做:
SELECT * FROM `exam_result` JOIN `course` ON `course`.`course_tab_id`=`exam_result`.`result_course` WHERE `exam_id` = '1' AND `result_status` = 1 GROUP BY `exam_result`.`exam_roll`, `course`.`course_tab_id` ORDER BY `exam_result`.`exam_roll` ASC, `course`.`course_id` ASC
为什么在SQL查询本身滚你不组它,只是使用这些数据绑定到你的HTML表格或任何你在UI – Sujith
使用'array_merge'使用显示器。 –
只需按roll和course_id命令'''SELECT * FROM result WHERE exam_id = 1 ORDER BY roll,course_id''' – Neodan