0

I am trying to generate a student tabulation sheet. How can I display students details with ranking according to Marks & GPA(Descending). currently I can display by either Marks or GPA with the following code:

 arsort($myGpa);
    foreach($myGpa as $x=>$myValue)
     { 
      ?>
      <tr>
        <td><?php echo $sn++; ?></td>

       <td><?php echo $myName[$x]; ?></td>
      <td><?php echo $myCadet[$x]; ?></td>

      <td><?php echo $myTotal[$x]; ?></td>
      <td><?php echo $myGrade[$x]; ?></td>
    <td><?php echo number_format($myValue,2); ?> </td>
    <td><?php //$position++;  
         $myposition = $position++;
         if($myposition == '1') { echo '1st'; }
        else if($myposition == '2') { echo '2nd'; }
        else if($myposition == '3') { echo '3rd'; }
         else echo $myposition.'th';

     ?> </td>   

     </tr>

and another thing is: if the marks & gpa are same then how to show the position ? thanks in advance.

  • can you post more of your code? where are myName,... set? you should probably sort on a higher level using multisort. additionally what is more important for ranking gpa or marks? – Roman Pickl Jan 12 '14 at 10:10

1 Answers1

0

actually.. I want to sort the students according to marks & gpa. currently my output is as follows:

Total Marks - Grade - GPA - Position
813 - A - 4.50 - 1
819 - A - 4.44 - 2
779 - A - 4.31 - 3
826 - A - 4.31 - 4

but as you see 2 students got same gpa(4.31) but different marks. I want the marks to be sorted when the gpa is same. that means if 2 students have same gpa then the position will be calculated according to marks.

currently I am using the following code(sort by GPA only)

 $myName[] = $student_name['name'];
             $myCadet[] = $stud['cadet_no'];
             $myTotal[] = $all_total;
             $myGrade[] = $final_grade;
             $myGpa[] = $final_gpa;
arsort($myGpa);
foreach($myGpa as $x=>$myValue)
 { 
  ?>
  <tr>
    <td><?php echo $sn++; ?></td>

   <td><?php echo $myName[$x]; ?></td>
  <td><?php echo $myCadet[$x]; ?></td>

  <td><?php echo $myTotal[$x]; ?></td>
  <td><?php echo $myGrade[$x]; ?></td>
<td><?php echo number_format($myValue,2); ?> </td>
<td><?php //$position++;  
     $myposition = $position++;
     if($myposition == '1') { echo '1st'; }
    else if($myposition == '2') { echo '2nd'; }
    else if($myposition == '3') { echo '3rd'; }
     else echo $myposition.'th';

 ?> </td>   

 </tr>

}