<?php
	include('db.php');

// Check connection
if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}
$name=$_GET["user"];
$sname=$_GET["studname"];
$button="submit";

$sql = "SELECT * FROM tbl_users WHERE  registration_id = '$name' AND first_name = '$sname'";
$result = $con->query($sql);

if ($result->num_rows > 0) 
{
	 while($row = $result->fetch_assoc()) 
	 {
		$department=$row['category'];
		$id=$row['registration_id'];
		$stname= $row['first_name'];
	 }
}

if($button=="submit")
	{
		$sql = "SELECT distinct subject,stud_id,exam_name,score,student_name  FROM `tbl_dummyresult` WHERE stud_id='$name' AND 	student_name = '$sname'ORDER BY subject;";
		$result = $con->query($sql);

		$result = $con->query($sql);
		if ($result->num_rows > 0) 
		{
			// output data of each row
			while($row = $result->fetch_assoc()) 
			{
				$item[] = array("subject" => $row['subject'],
				"score" => $row['score']);
			}
			
			$message=$item;
			$response=array('status' => "true", 'Message' => "Login success",'Register Number' => "$id",'Student Name' => "$sname",'Message' => "$department",'Result Details:' => $message);  
					echo json_encode($response);
			
		} 
		else 
		{
			$response=array('status' => "false", 'Message' => "No Data");
			echo json_encode($response);
		}
	}
$con->close();
?> 
