I have made a leaderboard for a quiz ordered by their score and I want to show the position of the user. How could I count how many rows are above them in the table in order to determine their position? This code only works when people don't have the same score. If 2 people both have the high score, both will see themselves as number 2.
function firstPlace() {
include 'connection.php';
$sql="SELECT * FROM Users WHERE Email='$_SESSION[email]'";
$result=mysqli_query($connection,$sql);
while($row1=mysqli_fetch_array($result)) {
if(isset($row1[4])) {
$score=$row1[4];
}
}
$sql2="SELECT * FROM Users WHERE Email='$_SESSION[email]'";
$result2=mysqli_query($connection,$sql2);
$sql1="SELECT * FROM Users WHERE Score >= $score ORDER BY Score DESC";
$result1=mysqli_query($connection,$sql1);
$numRows=mysqli_num_rows($result1);
while($row=mysqli_fetch_array($result2)) {
if($row[5]!="") {
$src1="photos/".$row[5];
}
else {
$src1='images/profile-pic.png';
}
echo "
<a class='logo' href='index.php'><img src='$src1' class='bigProfilePic' id='logo' alt='Profile pic'></a>
<h1>$numRows</h1>
<h2>$row[1]</h2>
<h3>$row[4]<span>Kms</span></h3>";
}