<?php 
$host = "localhost";
$user = "penuel_exam";
$pass = "admin@mail.com";
$db   = "penuel_exam";
$conne = null;

try {
  $conne = new PDO("mysql:host={$host};dbname={$db};",$user,$pass);
} catch (Exception $e) {
  
}




$servername = "localhost";
$username = "penuel_exam";
$password = "admin@mail.com";
$dbname = "penuel_exam";

// Create connection
$connn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$connn) {
  die("Connection failed: " . mysqli_connect_error());
}


$q = intval($_GET['q']);

$cono = mysqli_connect('localhost','penuel_penuel','vEqcN.6$yF(T');
if (!$cono) {
  die('Could not connect: ' . mysqli_error($cono));
}
$conon = mysqli_connect('localhost','penuel_exam','admin@mail.com');
if (!$conon) {
  die('Could not connect: ' . mysqli_error($conon));
}

mysqli_select_db($cono,"penuel_penuel");
$sql="SELECT * FROM students WHERE id = '".$q."'";
$result = mysqli_query($cono,$sql);

if($row = mysqli_fetch_array($result)) {
 $add_no=$row['Admission_num'];
 echo $add_no; 
  
	  mysqli_select_db($conon,"penuel_exam");
	$sql1="SELECT * FROM examinee_tbl WHERE exmne_email = '".$add_no."'";
	$result1 = mysqli_query($conon,$sql1);
	
	if($row1 = mysqli_fetch_array($result1)) {
	 $exmneId=$row1['exmne_id'];
	 $excorse_id=$row1['exmne_course'];
	// echo $exmneId; 
	      
	  
	    
                    $selTakenExam = $conne->query("SELECT * FROM exam_tbl et INNER JOIN exam_attempt ea ON et.ex_id = ea.exam_id WHERE exmne_id='$exmneId' and cou_id=$excorse_id ORDER BY ea.examat_id  ");

                    if($selTakenExam->rowCount() > 0)
                    {
                        while ($selTakenExamRow = $selTakenExam->fetch(PDO::FETCH_ASSOC)) { 
                             $examId=$selTakenExamRow['ex_id']; 
                               $over  = $selTakenExamRow['ex_questlimit_display'];
                                  echo $selTakenExamRow['ex_title']." ";  
                                  
                                  
                                  
                                   $selScore = $conne->query("SELECT * FROM exam_question_tbl eqt INNER JOIN exam_answers ea ON eqt.eqt_id = ea.quest_id AND eqt.exam_answer = ea.exans_answer  WHERE ea.axmne_id='$exmneId' AND ea.exam_id='$examId' AND ea.exans_status='new' ");
		                           
		                                echo $selScore->rowCount(); 
		                                
		                                   
		                                 
		                            echo "/";
		                            echo $over;
		                            echo "<br>";
		
                                  
                                  
                                  
                                  
                            
                         }
                    }
                    
                    

	  
	  
	  
	  
	  
	}
  
  
  
}





	 
// 	 check attempted exam 
// $sql1 = "SELECT * FROM exam_attempt where exmne_id ='$exmne_id'";
// $result1 = mysqli_query($connn, $sql1);

//             if (mysqli_num_rows($result1) > 0) {
//               // output data of each row
//               while($row1 = mysqli_fetch_assoc($result1)) {
                  
//                   $exam_id=$row1["exam_id"];
                  
//                   $sql2 = "SELECT * FROM exam_tbl where ex_id ='$exam_id'";
//                         $result2 = mysqli_query($connn, $sql2);
                        
//                         if (mysqli_num_rows($result2) > 0) {
//                             // output data of each row
//                             if($row2 = mysqli_fetch_assoc($result)) {
                                
//                         		$ex_id=$row2["ex_id"];
//                         		$ex_title=$row2["ex_title"];
//                             }
//                         }
                  
//                 echo  	$ex_title. "<br>";
//               }
//             }

 ?>