<?php session_start() ?>

<?php

$tyr=$_SESSION['num'];



//make the database connection

include('config.php');

$sql = "select * from access where userid = '$tyr' ";

 $data = mysqli_query($conn,$sql);



$rows = mysqli_num_rows($data);



if($rows <= 0){

   do_alert("user does not exist contact system admin");

}

else{



while($row= mysqli_fetch_array($data))

{



$serial=  $row['name'];

 $input= $row['userid'];

$class=  $row['class'];

 $arm= $row['arm'];

 $email= $row['date'];

$clay="$class$arm";

$dfrd="subjects";

$sdc="$clay$dfrd";

$_SESSION['name']=$serial;

$claff=$clay;

$_SESSION['num']=$input;

$_SESSION['clay']=$clay;

$_SESSION['email']=$email;

$_SESSION['sdz']=$sdc;



}



}



$ubjects="subjects";

$sdc="$clay$ubjects";





$_SESSION['subb']=$sdc;

$sql = "select subjects,class,type

 from `subjects` where staffid='$tyr' ";

 $data = mysqli_query($conn,$sql);







$rows4 = mysqli_num_rows($data);



$lcclass=strtolower($clay);

$_SESSION['lclay']=$lcclass;



$sql = "select * from `beva1` where password='$lcclass' ";

 $data = mysqli_query($conn,$sql);







$rows44 = mysqli_num_rows($data);



// Above will output ---- > testValue 











$sql = "SELECT MAX(serialno) AS maxid FROM subjects ";

          

          $data = mysqli_query($conn,$sql);

    $result = mysqli_fetch_assoc($data);



          





$pe=  $result['maxid'];





$se= $pe + 1;



$eer=$_SESSION['num'];

$obo10=$eer;



$sql = "SELECT MAX(extime) AS maxidi FROM `t_$obo10`";

          

 $result1i = mysqli_query($conn,$sql);

$resulto = mysqli_fetch_assoc($result1i);



          









          

$rows1=  $resulto['maxidi'];



$tpe=  $rows1 + 1;













	



$sct="TERM EXAMINATION";

$aas="$class$arm";

$asut="subjects";

















?>



<?php

$stu=$_POST['idty'];

$tyr=$_SESSION['num'];

$_SESSION['numi']=$stu;





//make the database connection

include('config.php');

$sql = "select * from `t_$obo10` where serialno = '$stu'  ";

$data = $conn->query($sql); 



$rows = mysqli_num_rows($data);

while($row = $data->fetch_assoc())

{



$ssubj=  $row['subjects'];

$class=  $row['class'];

$arm= $row['type'];

 

$clafg="$class$arm";



$_SESSION['class']=$clafg;

$_SESSION['sub']=$ssubj;

}



$sql = "select * from `beva1` where regno= '$stu'";

$data = $conn->query($sql); 



$rows = mysqli_num_rows($data);













$sql = "UPDATE `$clafg` set tot=(code+weeklytest+ex) WHERE regno='$stu'";

					$data = $conn->query($sql);



?>



 <?php

include ('config.php');

$subj=$_POST['idty'];

$query = "SELECT Name,subjects,code as CAT1,weeklytest as CA1,cod as CAT2,week1 as CA2,ex as EXAM FROM `$clafg` where subjects='$ssubj'";

$result = mysqli_query($conn, $query);



$num_column = mysqli_num_fields($result);		



$csv_header = '';

for($i=0;$i<$num_column;$i++) {

    $csv_header .= '"' . mysqli_fetch_field_direct($result,$i)->name . '",';

}	

$csv_header .= "\n";



$csv_row ='';

while($row = mysqli_fetch_row($result)) {

	for($i=0;$i<$num_column;$i++) {

		$csv_row .= '"' . $row[$i] . '",';

	}

	$csv_row .= "\n";

}	



/* Download as CSV File */

header('Content-type: application/csv');

header('Content-Disposition: attachment; filename=mysheet.csv');

echo $csv_header . $csv_row;

exit;

?>

