<?php
   $grd=$kla;
   $exa=$ex;
   
   $sql = "SELECT * FROM pupils where Claz='$grd' AND Status='Active'";
   $result = $con->query($sql);
   if ($result->num_rows > 0) 
   {
   $sql2 = "SELECT * FROM CBC2 where Grad='$grd' AND EID='$exa'";
   $result = $con->query($sql2);
   if ($result->num_rows > 0) 
   {
    
   $sqll = "SELECT * FROM examsetting  WHERE examid='$exa' AND Grad='$grd'";
   $result = $con->query($sqll);
   while($row = $result->fetch_assoc()) 
   {
   $tota=$row['TT'];
   } 
   
   
   $sqll = "SELECT * FROM Exam WHERE id='$exa'";
   $result = $con->query($sqll);
   while($row = $result->fetch_assoc()) 
   {
   $tito=$row['Title'];
   } 
    
   ?>
<table class="table table-bordered" id="tablecbc" style="font-size:12px;font-family:Tahoma;width:auto">
   <thead>
      <tr>
         <th>#</th>
         <th>Pupil's Details</th>
         <th>Maths</th>
         <th>Eng</th>
         <th>Kisw</th>
         <th>CRE</th>
         <th>SS</th>
         <th>Scie & Tech</th>
         <th>Creat' Arts</th>
         <th>Agri & Nutrition</th>
         <th class="bg-secondary">Total</th>
         <th class="bg-secondary">Out Of</th>
         <th class="bg-secondary">Rubric</th>
         <th class="bg-success">Position</th>
      </tr>
   </thead>
   <tbody id="" style="font-size:11px;font-family:Arial">
      <?php
         $sql = "SELECT CBC2.*, pupils.Names as nm, pupils.AdmNo as adm from CBC2 left join pupils ON CBC2.PID=pupils.count where CBC2.EID='$exa' AND Grad='$grd' AND pupils.Status='Active' AND CBC2.TMks !='' ORDER BY CBC2.TMks DESC";
         $result = $con->query($sql);
             $cnt=1;
             $pos=1;
         	while($row = $result->fetch_assoc()) 
         	{
             ?>	
             
       <!--tr>
         <td><?php echo $cnt; ?></td>
         <td><?php  echo $row['nm'].' ('.$row['adm'].')'; ?></td>
         <td> <strong><?php echo $row['Math']; ?> </strong> - <?php echo $row['MA1']; ?></td>
         <td> <strong><?php echo $row['Eng']; ?> </strong> - <?php echo $row['EN1']; ?></td>
         <td> <strong><?php echo $row['Kis']; ?> </strong> - <?php echo $row['KS1']; ?></td>
         <td> <strong><?php echo $row['CRE']; ?> </strong> - <?php echo $row['CR1']; ?></td>
         <td> <strong><?php echo $row['SS']; ?> </strong> - <?php echo $row['SS1']; ?></td>
         <td> <strong><?php echo $row['ST']; ?> </strong> - <?php echo $row['ST1']; ?></td>
         <td> <strong><?php echo $row['CA']; ?> </strong> - <?php echo $row['CA1']; ?></td>
         <td> <strong><?php echo $row['AN']; ?> </strong> - <?php echo $row['AN1']; ?></td>
         <td style="background-color:#d1e0e0"> <strong class="text-danger"><?php echo $row['TMks']; ?></strong></td>
         <td style="background-color:#d1e0e0"> <strong><?php echo $tota; ?></strong></td>
         <td style="background-color:#d1e0e0"> <strong class="text-danger"><?php echo $row['TRub']; ?></strong></td>
         <td class="bg-success text-white">
            <strong><?php echo $pos; ?></strong>
         </td>
      </tr-->       
             
             
             
      <tr>
         <td><?php echo $cnt; ?></td>
         <td><?php  echo $row['nm'].' ('.$row['adm'].')'; ?></td>
         <td> <strong><?php echo $row['Math']; ?> </strong> </td>
         <td> <strong><?php echo $row['Eng']; ?> </strong> </td>
         <td> <strong><?php echo $row['Kis']; ?> </strong></td>
         <td> <strong><?php echo $row['CRE']; ?> </strong></td>
         <td> <strong><?php echo $row['SS']; ?> </strong></td>
         <td> <strong><?php echo $row['ST']; ?> </strong></td>
         <td> <strong><?php echo $row['CA']; ?> </strong> </td>
         <td> <strong><?php echo $row['AN']; ?> </strong></td>
         <td style="background-color:#d1e0e0"> <strong class="text-danger"><?php echo $row['TMks']; ?></strong></td>
         <td style="background-color:#d1e0e0"> <strong><?php echo $tota; ?></strong></td>
         <td style="background-color:#d1e0e0"> <strong class="text-danger"><?php echo $row['TRub']; ?></strong></td>
         <td class="bg-success text-white">
            <strong><?php echo $pos; ?></strong>
         </td>
      </tr>
      <?php
         $cnt=$cnt+1;
         $pos=$pos+1;
         }
         ?>
      <tr>
         <td colspan="14">
         </td>
      </tr>
   </tbody>
</table>
<input type="hidden" id="examuname"  value="<?php echo  $tito.'-'.$grd ?>" />
<button class="btn btn-default pull-right" id="btndown67">Download Results <i class="fa fa-cloud-download"></i></button>
<?php
   }else
   {
       
   echo 'No exam results saved';    
       
   }
   }
   else {
   	echo "0 results";
   }
   	
   //mysqli_close($con);
   
   ?>