我有这张桌子
学生表
ID | NAME | CLASS
1 | SARA | 1
2 | AMAR | 2
3 | HERRY| 1
SUBJECT 表//
ID | SUBJECT_NAME|
1 | A |
2 | B |
3 | C |
每个科目的学生分数都可以包含在该表中。
年中
student_id |score of subject|
|A |B | C |
1 | 33 |44 | 55 |
2 | 66 |77 | 88 |
3 | 99 | 0 | 0 |
我有两个阵列
$学生
<?php
$sel_query3="Select * from STUDENT ORDER BY ID;"; //FROM TABLE STUDENT
$result3 = @mysqli_query($con,$sel_query3);
while($row2 = @mysqli_fetch_assoc($result3)){
$student = [
"id":"$row2['ID']",
"name":"$row2['NAME']",
];
}
?>
输入:
$ student = [id => 1,name => SARA]
$ marks
<?php
$sel_query4="Select * from SUBJECT ORDER BY SUBJECT_NAME;"; //FROM TABLE SUBJECT
$result4 = @mysqli_query($con,$sel_query4);
while($row3 = @mysqli_fetch_assoc($result4)){
$sel_query5="Select * from MIDYEAR ORDER BY STUDENT_ID;"; //FROM TABLE MID YEAR TO GET STUDENT SCORE in each subject
$result5 = @mysqli_query($con,$sel_query5);
while($row4 = @mysqli_fetch_assoc($result5)){
$s = $row3['SUBJECT_NAME'];
$score = [
"$row3['SUBJECT_NAME']":"$row4[$s]",
];
}
?>
输入:
$ score = [A => 33,B => 44,C => 55];
我想像这样合并数组
$test = [ id => 1, name => SARA, A => 33, B => 44, C => 55 ], [ id => 2, name => AMAR, A => 66, B => 77, C => 88 ], [ id => 3, name => HENRY, A => 99, B => 0, C => 0 ];
请帮助!感谢帮助:)