Golf Scores

I play for a golf team online and we had a PHP scoring system designed for the team. Unfortunately we can no longer contact the PHP designer who designed the scoring system, so here is my Question. In golf as you know if you score below par you get a - score for your round -1 -2 -3 excetra, the scores in the score system show up with the largest - score at the bottom of the scorecard and we would like the highest - score to be at the top in descending order. No one in the team I am in know anything about PHP so I saw your help line and joined your forum in the hope that you could help.Here is the PHP page where the code is situated if possible what parts of the code needs to be changed to help the team obtain its goals.It does say in the code that it is descending so maybe it needs to be Ascending I do not know.Any help would be very much appreciated we have an average age of 65 so all this PHP stuff just goes over our heads lol.

  • Class represents the leaderboard
    */
    [php]final class Leaderboard {
    private $players;
    private $season;

    function __construct($seasonID) {
    if ($seasonID != “”) {
    $this->season = $seasonID;

             $sql = "SELECT DISTINCT(playerID) FROM rounds WHERE seasonName = ?";
             $connection = Connection::getConnection();
             $stmt = $connection->prepare($sql);
             $stmt->bind_param("s", $this->season);
             $stmt->execute();
             $stmt->bind_result($playerID);
             
             //setup weekly round scores for a season in player data
             while ($stmt->fetch()) {
                  $player = new Player();
                  $player->setID($playerID);
                  $this->players[] = $player;
             }          
             $stmt->close();
             
             if (count($this->players) <= 0) {
                  echo "<tr>";
                  echo "<td colspan='7' style='text-align: center'>No data to display for this season</td>";
                  echo "</tr>";
             }
        }
    

    }

    //Used to sort the cumulative score in descending order
    function selection_sort(&$arr) {
    $n = count($arr);
    for($i = 0; $i < count($arr); $i++) {
    $min = $i;
    for($j = $i + 1; $j < $n; $j++)
    if($arr[$j]->getSeasonTotal($this->season) > $arr[$min]->getSeasonTotal($this->season))
    $min = $j;
    $tmp = $arr[$min];
    $arr[$min] = $arr[$i];
    $arr[$i] = $tmp;
    }
    }

    public function show() {
    if (count($this->players) > 0) {
    $this->selection_sort($this->players);
    foreach($this->players as $player) {
    $player->initRoundScores($this->season);
    echo “”;
    echo “” . $player->getData(“golferName”) . “”;
    echo “” . $player->getData(“round1”) . “”;
    echo “” . $player->getData(“round2”) . “”;
    echo “” . $player->getData(“round3”) . “”;
    echo “” . $player->getData(“round4”) . “”;
    echo “” . $player->getData(“weekTotal”) . “”;
    echo “” . $player->getSeasonTotal($this->season) . “”;
    echo “”;
    }
    }
    }
    }[/php]
    I forgot to say if you need the full PHP document there are about 8 or 9 pages I can send you the full script if you need them to work on using an online file transfer. Below is a picture on a test I have done the -105 should be at the top.Thank you in advance. TeeShot


SnapCrab_NoName_2018-4-2_16-17-20_No-00.png

Have to test it, but it looks like you just need to make this change,

[php] function selection_sort(&$arr) {
$n = count($arr);
for($i = 0; $i < count($arr); $i++) {
$min = $i;
for($j = $i + 1; $j < $n; $j++)
// Changed from greater than to less than equal to
if($arr[$j]->getSeasonTotal($this->season) <= $arr[$min]->getSeasonTotal($this->season))
$min = $j;
$tmp = $arr[$min];
$arr[$min] = $arr[$i];
$arr[$i] = $tmp;
}
}
[/php]

Thank you very much for your reply, I will try that, very much appreciated astonecipher.

I wish to thank you astonecipher it worked great. The golf team will be overjoyed, this is very much appreciated thank you thank you.

Just to show what you did for us astonecipher. We cannot thank you enough.


Sponsor our Newsletter | Privacy Policy | Terms of Service