I Create a exam result sheet I want to show Positions all of student like 1st, 2nd, 3rd, .... like his percentage.
This is my code.
<table>
<thead>
<tr>
<th>Name</th>
<?php $total_sub = 0; ?>
<?php foreach ($subject as $sub): ?>
<?php if ($sub['sub_status']==1): ?>
<th colspan="2"> <center><?php echo $sub['sub_code']; ?></center></th>
<?php
$total_sub = $total_sub+1;
endif; ?>
<?php endforeach; ?>
<th colspan="2"><center> Total </center></th>
<th><center>Per% </center></th>
<th><center>Position</center></th>
<!-- onclick="sortTable(<?php echo $total_sub+2 ?>)" -->
</tr>
<tr>
<th>
</th>
<?php foreach ($subject as $sub): ?>
<?php if ($sub['sub_status']==1): ?>
<th> <center> OM </center></th>
<th> <center> TM </center> </th>
<?php endif; ?>
<?php endforeach; ?>
<th> <center> OM </center> </th>
<th> <center> TM </center> </th>
<th><center></center></th>
<th> <center> </center></th>
</tr>
</thead>
<tbody>
<?php foreach ($student as $std): ?>
<?php if ($std['enrolment_status']==1): ?>
<tr>
<?php
$total = 0;
$obtain = 0;
?>
<td>
<?php echo $std['student_registration_name'] ?>
</td>
<?php foreach ($subject as $sub): ?>
<?php if ($sub['sub_status']==1): ?>
<?php
$rt='N';
$rtt ='N';
$code = $std['en_id']."-".$sub['sub_id'];
foreach ($result as $res) {
$rest = $res['enrolment_en_id']."-".$res['subject_sub_id'];
if ($code === $rest) {
$rt = $res['er_obtain'];
$rtt = $res['er_total'];
$total = $total + $res['er_total'];
if ($rt == '-1') {
$obtain = $obtain + 0;
}else if($rt == '-2'){
$obtain = $obtain + 0;
}else {
$obtain = $obtain + $res['er_obtain'];
}
}
}
?>
<td><center><?php
if ($rt == '-1') {
echo "A";
}else if($rt == '-2'){
echo "-";
}else {
echo $rt;
}
?> </center></td>
<td><center><?php
if ($rt == '-1') {
echo "A";
}else if($rt == '-2'){
echo "-";
}else {
echo "$rtt";
}
?> </center></td>
<?php endif; ?>
<?php endforeach; ?>
<td><center><?php echo $obtain ?> </center></td>
<td><center><?php echo $total ?> </center></td>
<td>
<center>
<?php
if ($total!=0) {
$per = $obtain/$total*100;
echo number_format($per, 1);
echo " %";
}else {
echo "0 %";
}
?>
</center>
</td>
<td>
<center>
</center>
</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
I'm trying to get the ranking position of a student by percentage. For example if student 1 has 90.0% with a total of 100 points and student 2 has 80.5% with a total of 100 points. Student 1 will ranking position higher than student 2. I was wondering how would I be able to do this?