Here is how to use an open API to display the AFL Ladder with PHP.
The concept is simple; Call the ladder api, start a table and then in a foreach loop go through the results.
The foreach loop represents a row for each loop, this is the same as building a table from MySQL data except this is with JSON formatted data.
As always dont abuse any open API’s and cache them in a database where possible.
PHP code is:
";//Start table and have headers outside of the loop foreach ($data['positions'] as $val) {//loop echo " # Team Points Wins Lost Played Percent Points for Points against Last 5 vs next ";//start row $team = $val['teamName']['teamName']; $position = $val['thisSeasonRecord']['ladderPosition']; $points = $val['thisSeasonRecord']['aggregatePoints']; $percent = $val['thisSeasonRecord']['percentage']; $next_vs = $val['nextOpponent']['teamName']; $points_for = $val['pointsFor']; $points_against = $val['pointsAgainst']; $last_5_wins = $val['lastFiveGamesRecord']['wins']; $last_5_draws = $val['lastFiveGamesRecord']['draws']; $last_5_losses = $val['lastFiveGamesRecord']['losses']; $wins = $val['thisSeasonRecord']['winLossRecord']['wins']; $losses = $val['thisSeasonRecord']['winLossRecord']['losses']; $played = $val['thisSeasonRecord']['winLossRecord']['played']; if ($position > 8) { $row_color = '#de7c8d';//if position greater than 8 (not in finals position) } else { $row_color = '#94dea3'; } echo " ";//end row } echo "";//close table$position "; echo "$team "; echo "$points "; echo "$wins "; echo "$losses "; echo "$played "; echo "$percent "; echo "$points_for "; echo "$points_against "; echo "W:$last_5_wins L:$last_5_losses D:$last_5_draws "; echo "$next_vs "; echo "
Some minimal styling (add above
Gives you this
A drained and empty Kennington reservoir images from a drone in early July 2024. The…
Merrimu Reservoir from drone. Click images to view larger.
Some early September spring shots from a bushwalk, It is still too early for wildflowers.
I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…
If you ever needed a simple solution in Laravel to delete an entire directory and…
How to enforce only one user to register or be registered in a Laravel web…