This is the simplified code for the scoreboard. What I am trying to build is a table that auto sorts itself by Total Points and assigns the rank of 1 for the lowest score and increments rank up from there until everyone has a rank. If 2 people have the same score the rank would be a T then the number.
<?php
$sql_score = $mysqli->query("SELECT * from event_scoreboard WHERE workoutid = '$work_out[$workout_counter]'");
$rowcount1=mysqli_num_rows($sql_score);
$array = array();
while($objscore = $sql_score->fetch_object()) {
$score = $objscore->score;
$total_score += $score * 3;
}
$values = array($total_score);
$ordered_values = $values;
echo rsort($ordered_values);
foreach ($values as $key => $value) {
foreach ($ordered_values as $ordered_key => $ordered_value) {
if ($value === $ordered_value) {
$key = $ordered_key;
break;
}
}
echo $value . '- Rank: ' . ((int) $key + 1) . '<br/>';
}
?>
The test code below works fine, but how can we achieve the same output by inserting those outputs from the while condition into a multi-dimentional array ex. $values = array($total_score);
Right now, i'm getting this output below. It only displays the array index['0'] which is why the Rank is 1 in all output.
13087 - Rank: 1
11029 - Rank: 1
110359 - Rank: 1
17035 - Rank: 1
19702 - Rank: 1
1702 - Rank: 1
196 - Rank: 1
19 - Rank: 1
110266 - Rank: 1
Working example to display the ranking based on score (currently DESC but it needs to be in ASC order - lowest score would be the rank # 1)
$values = array();
$values[0] = 13389;
$values[1] = 71298;
$values[2] = 234;
$values[3] = 9069;
$values[4] = 9936;
$values[5] = 2673;
$values[6] = 234;
$values[7] = 234;
$values[8] = 11634;
$values[9] = 1470;
$ordered_values = $values;
echo rsort($ordered_values);
foreach ($values as $key => $value) {
foreach ($ordered_values as $ordered_key => $ordered_value) {
if ($value === $ordered_value) {
$key = $ordered_key;
break;
}
}
echo $value . '- Rank: ' . ((int) $key + 1) . '<br/>';
}