0
我需要合併兩個數組以打印html 中的數據或直接打印數據,但使用我的代碼打印重複的數據。合併兩個數組以打印html中的數據
這是陣列來自數據庫:
Array
(
[Course name] => English 4A
[Grade out of weight exam] => 47.25
)
Array
(
[Course name] => Humanities 4A
[Grade out of weight exam] => 45.00
)
Array
(
[FullName] => Adam Sherif Wahba Ibrahim Botros
[Course name] => English 4A
[Grade name] => 2nd Term
[Grade] => 74.25
[MAX] => 100.00
[Percentage] => 74.25
[Grade out of weight] => 247.50
[gi.aggregationcoef*100] => 333.33300
)
Array
(
[FullName] => Adam Sherif Wahba Ibrahim Botros
[Course name] => Humanities 4A
[Grade name] => 2nd Term
[Grade] => 73.20
[MAX] => 100.00
[Percentage] => 73.20
[Grade out of weight] => 244.00
[gi.aggregationcoef*100] => 333.33000
)
這是我的HTML代碼和PHP
<table border='1'>
<tr class="tr">
<th class="th"> subject </th>
<th class="th"> student's Work out of </th>
<th class="th"> exam out of </th>
<th class="th"> total out of </th>
<th class="th"> Grade </th>
</tr>
<?php
$sql = "SELECT
c.fullname AS'Course name' ,
ROUND(ROUND(gg.finalgrade/gg.rawgrademax * 100 ,2) *(gi.aggregationcoef*100)/100,2) AS 'Grade out of weight exam'
FROM
mdl_course AS c
JOIN mdl_grade_items AS gi ON gi.courseid = c.id
JOIN mdl_grade_grades AS gg ON gg.itemid = gi.id
JOIN mdl_user AS u ON u.id = gg.userid
WHERE gi.courseid = c.id AND gi.itemname in ('2nd Term EXAM')
AND gi.itemtype = 'Category' and u.id = '5'";
$result = $conn->query($sql);
while($row = $result->fetch_assoc())
{
extract($row);
echo '<pre>';
print_r($row) ;
echo '</pre>';
}
///////////////// second SQL Get 2nd term
$sql2 = "SELECT
CONCAT(firstname, ' ', lastname) AS FullName , c.fullname AS'Course name' , gi.itemname AS 'Grade name',
ROUND(gg.finalgrade,2) AS Grade
,ROUND(gg.rawgrademax,2) AS MAX, ROUND(gg.finalgrade/gg.rawgrademax * 100 ,2) AS Percentage
,ROUND(ROUND(gg.finalgrade/gg.rawgrademax * 100 ,2) *(gi.aggregationcoef*100)/100,2) AS 'Grade out of weight'
,gi.aggregationcoef*100
FROM
mdl_course AS c
JOIN mdl_grade_items AS gi ON gi.courseid = c.id
JOIN mdl_grade_grades AS gg ON gg.itemid = gi.id
JOIN mdl_user AS u ON u.id = gg.userid
WHERE gi.courseid = c.id AND gi.itemname in ('2nd Term')
AND gi.itemtype = 'Category' and u.id = '5'"
;
$result2 = $conn->query($sql2);
while($row2 = $result2->fetch_assoc())
{
extract($row2);
echo '<pre>';
print_r($row2) ;
echo '</pre>';
?>
<tr class="tr">
<td class="td"><?php echo $row2["Course name"]; ?></td>
<td class="td"><?php echo ($row2["Grade out of weight"] - $row["Grade out of weight exam"]); ?></td>
<td class="td"><?php echo $row["Grade out of weight exam"]; ?></td>
<td class="td"><?php echo $row2["Grade out of weight"]; ?></td>
<td class="td"><?php echo $row[""]; ?></td>
<?php
}
?>
<td class="td"> </td>
</tr>
</table>
瑪吉=>合併,拖=>二,更正和更新您的問題請。 –
請編輯你的問題,你的代碼是不可讀的。 –