<?php
	include('../include/config.php');
	$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
    $timenow=$date->format('Y-m-d H:i:s');
    $timenow2=$date->format('Y-m-d');
    $exa=$_POST['exa'];
    $grd=$_POST['grd'];

    $sql = "SELECT * FROM pupils where Claz='$grd' AND Status='Active'";
	$result = $con->query($sql);
	if ($result->num_rows > 0) 
	{
	$sql2 = "SELECT * FROM CBC where Grad='$grd' AND EID='$exa'";
	$result = $con->query($sql2);
	if ($result->num_rows > 0) 
	{
	 ?>
	 <table class="table" id="" style="font-size:12px;font-family:Tahoma">
     <thead>
         <tr>
             <th>#</th>
             <th>Pupil's Details</th>
             <th>Maths</th>
             <th>Eng</th>
             <th>Kisw</th>
             <th>Int' L. Areas</th>
             <th>Creative A' & SS</th>
             <th>Save</th>
         </tr>
     </thead>
     <tbody id="" style="font-size:11px;font-family:Arial">
	 <?php
	$sql = "SELECT CBC.*, pupils.Names as nm, pupils.AdmNo as adm from CBC left join pupils ON CBC.PID=pupils.count where CBC.EID='$exa' AND CBC.Grad='$grd'";
	$result = $con->query($sql);
	    $cnt=1;
		while($row = $result->fetch_assoc()) 
		{
    ?>	
		<tr>
			<td><?php echo $cnt; ?></td>
			<td><?php  echo $row['nm'].' ('.$row['adm'].')'; ?></td>
			<td><input type="text" class="sc scemat" value="<?php echo $row['Math']; ?>" onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc sceng" value="<?php echo $row['Eng']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc sckis" value="<?php echo $row['Kis']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc ila" value="<?php echo $row['ILA']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc cass" value="<?php echo $row['CA']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>

			<td><input type="hidden" class="pupilidholder"  value="<?php echo $row['PID']; ?>" />
			    
			    <i class="fa fa-save btn text-info fafasave" ></i></td>
		</tr>
    <?php
    $cnt=$cnt+1;
	}
	?>
	</tbody>
 </table>
 <?php
	}else
	{
	  ?>
 <table class="table" id="" style="font-size:12px;font-family:Tahoma">
     <thead>
         <tr>
             <th>#</th>
             <th>Pupil's Details</th>
             <th>Maths</th>
             <th>Eng</th>
             <th>Kisw</th>
             <th>Int' L. Areas</th>
             <th>Creative A' & SS</th>
             <th>Save</th>
         </tr>
     </thead>
     <tbody id="" style="font-size:11px;font-family:Arial">
	  <?php
	     $sql = "SELECT * FROM pupils where Claz='$grd' AND Status='Active'";
	$result = $con->query($sql);
	    $cnt=1;
		while($row = $result->fetch_assoc()) 
		{
    ?>	
		<tr>
			<td><?php echo $cnt; ?></td>
			<td><?php  echo $row['Names'].' ('.$row['AdmNo'].')'; ?></td>
			<td><input type="text" class="sc scemat" onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc sceng"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc sckis"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc ila"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc cass"  onkeypress="return /[0-9]/i.test(event.key)" /></td>

			<td><input type="hidden" class="pupilidholder"  value="<?php echo $row['count']; ?>" />
			    
			    <i class="fa fa-save btn text-info fafasave" ></i></td>
		</tr>
    <?php
    $cnt=$cnt+1;
	}
	?>
	 </tbody>
 </table>
	<?php
	}

	}
	else {
		echo "0 results";
	}
	mysqli_close($con);

?>