<?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 Gradeseven where Grad='$grd' AND EID='$exa'";
	$result = $con->query($sql2);
	if ($result->num_rows > 0) 
	{
	 ?>
	 <table class="table table-bordered" id="" style="font-size:12px;font-family:Tahoma">
     <thead>
         <tr class="alert-success">
             <th>#</th>
             <th>Pupil's Details</th>
             <th>Maths</th>
             <th>Eng</th>
             <th>Kisw</th>
             <th>I. Scie</th>
             <th>S.Studies</th>
             <th>B. Studies</th>
             <th>Agriculture</th>
             <th>L. Skills</th>
             <th>Pre-Tech</th>
             <th>Health E.</th>
             <th>C.R.E</th>
             <th>P.E</th>
             <th>Optional</th>
             <th>Save</th>
         </tr>
     </thead>
     <tbody id="" style="font-size:11px;font-family:Arial">
	 <?php
	$sql = "SELECT Gradeseven.*, pupils.Names as nm, pupils.AdmNo as adm from Gradeseven left join pupils ON Gradeseven.PID=pupils.count where Gradeseven.EID='$exa' AND Gradeseven.Grad='$grd' ORDER BY Mat DESC";
	$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" value="<?php echo $row['Mat']; ?>" class="sc math" onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc english" value="<?php echo $row['Eng']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc kisw" value="<?php echo $row['Kis']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc Inter" value="<?php echo $row['ISc']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc SoS" value="<?php echo $row['SS']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc BS" value="<?php echo $row['BS']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc agri" value="<?php echo $row['Ang']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc lifeski" value="<?php echo $row['LS']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc ptech" value="<?php echo $row['PreT']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc HE" value="<?php echo $row['HE']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc cre" value="<?php echo $row['CRE']; ?>" onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc pee" value="<?php echo $row['PE']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td>
			   <select id="" style="font-size:12px"  class="opt" required >
               <option value="<?php echo $row['OptSub']; ?>"><?php echo $row['OptSub']; ?></option>
                <option value="">---</option>
                <option value="Computer Science">Computer Science</option>
                <option value="Home Science">Home Science</option>
               </select>
			    
			    <input type="text" class="sc optmks" value="<?php echo $row['Mks']; ?>"  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 saveseven" ></i>
			 </td>
		</tr>
    <?php
    $cnt=$cnt+1;
	}
	?>
	</tbody>
 </table>
 <?php
	}else
	{
	  ?>
 <table class="table table-bordered" id="" style="font-size:12px;font-family:Tahoma">
     <thead>
         <tr class="alert-success">
             <th>#</th>
             <th>Pupil's Details</th>
             <th>Maths</th>
             <th>Eng</th>
             <th>Kisw</th>
             <th>I. Scie</th>
             <th>S.Studies</th>
             <th>B. Studies</th>
             <th>Agriculture</th>
             <th>L. Skills</th>
             <th>Pre-Tech</th>
             <th>Health E.</th>
             <th>C.R.E</th>
             <th>P.E</th>
             <th>Optional</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 math" onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc english"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc kisw"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc Inter"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc SoS"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc BS"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc agri"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc lifeski"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc ptech"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc HE"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc cre"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td><input type="text" class="sc pee"  onkeypress="return /[0-9]/i.test(event.key)" /></td>
			<td>
			    <select id="" style="font-size:12px"  class="opt" required >
                <option value="">---</option>
                <option value="Computer Science">Computer Science</option>
                <option value="Home Science">Home Science</option>
               </select>
			    
			    <input type="text" class="sc optmks"  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 saveseven" ></i>
			</td>
		</tr>
    <?php
    $cnt=$cnt+1;
	}
	?>
	 </tbody>
 </table>
	<?php
	}

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

?>