<?php 
	$id = (isset($_GET['id']) ? $_GET['id'] : '');
	require_once ('process/dbh.php');
	$sql = "SELECT id, firstName, lastName,  points FROM employee, score WHERE score.eid = employee.id order by score.points desc";
	$result = mysqli_query($conn, $sql);
?>



<html>
<head>
	<title>Leader Board</title>
	<link rel="stylesheet" type="text/css" href="css/styleemplogin.css">
	<link href="https://fonts.googleapis.com/css?family=Lobster|Montserrat" rel="stylesheet">
</head>
<body>
	<header>
		<nav>
			<h1>Leader Board</h1>
			<ul id="navli">
			<li><a class="homeblack" href="index.html"><span style="color:rgb(71, 14, 4);">Home</span></a></li>
				<li><a class="homered" href="leaderboard.php"><span style="color:rgb(71, 14, 4);">Score</span></a></li>
				<li><a class="homeblack" href="alogin.html"><span style="color:rgb(71, 14, 4);">Admin</span></a></li>
			</ul>
		</nav>
	</header>
	<div class="divider"></div>
	<div id="divimg">
	<div>

		    	<h2 style="font-family: 'Montserrat', sans-serif; font-size: 25px; text-align: center;">Candidate Leaderboard </h2>
    	<table>

			<tr bgcolor="#000">
				<th align = "center">Rank</th>
				<th align = "center">Cand. ID</th>
				<th align = "center">Name</th>
				<th align = "center">Points</th>
				

			</tr>

			

			<?php
				$seq = 1;
				$rank=0;
				$row=0;
				$last_score=false;
				while ($employee = mysqli_fetch_assoc($result)) {
					$row++;
					if($last_score!=$employee['points']){
						$last_score=$employee['points'];
						$rank=$row;
					}

					echo "<tr>";
					echo "<td>".$rank."</td>";
					echo "<td>".$employee['id']."</td>";
					
					echo "<td>".$employee['firstName']." ".$employee['lastName']."</td>";
					
					echo "<td>".$employee['points']."</td>";
					
					$seq+=1;
				}


			?>

		</table>
	</div>
	</h2>		
	</div>
</body>
</html>