A developer provided me with the following PHP file (although I have removed the API key and Secret):
/**
* League Championships
*/function fetch_league_table(){// Replace with your actual API credentials
$apiKey ='xxxx';
$secret ='xxxx';// Generate a digital signature (sig) using the current timestamp
$timestamp = time();
$sig = hash_hmac('sha256', $timestamp, $apiKey . $secret);// API endpoint and query parameters
$apiUrl ='https://secure.rugby-league.com/api/leaguetable';
$queryParams =['compID'=>4,// Replace with the appropriate competition ID'sig'=> $sig
];// Build the full URL
$urlWithParams = $apiUrl .'?'. http_build_query($queryParams);// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlWithParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER,['Accept: application/json','x-api-key: '. $apiKey,'sig: '. $sig
]);// Execute the API request
$response = curl_exec($ch);// Check for errorsif(curl_errno($ch)){return'Error fetching data: '. curl_error($ch);}
curl_close($ch);// Decode JSON response
$data = json_decode($response,true);// Handle response and build HTML outputif($data['status']!==200){return'No data found.';}
$leagueTable = $data['data']['table'];
$output ="<h2>". $data['data']['competition']." - ". $data['data']['season']."</h2>";
$output .="<table border='1' cellpadding='5' cellspacing='0'><thead><tr>";
$output .="<th>Position</th><th>Team</th><th>Played</th><th>Wins</th><th>Losses</th><th>Draws</th><th>Points</th></tr></thead><tbody>";foreach($leagueTable as $position => $team){if($position ==='deductions')continue;
$output .="<tr>";
$output .="<td>". $position ."</td>";// Fetch the logo URL from the API response
$logoUrl = isset($team['logo'])? $team['logo']:'';
$logoHtml = $logoUrl ?"<img src='$logoUrl' alt='{$team['teamName']} logo' style='height:20px; margin-right:10px;'>":'';
$output .="<td><strong>". $logoHtml . $team['teamName']."</strong></td>";
$output .="<td>". $team['P']."</td>";
$output .="<td>". $team['W']."</td>";
$output .="<td>". $team['L']."</td>";
$output .="<td>". $team['D']."</td>";
$output .="<td>". $team['PTS']."</td>";
$output .="</tr>";}
$output .="</tbody></table>";// Display deductions if availableif(isset($leagueTable['deductions'])){
$output .="<h3>Deductions</h3><ul>";foreach($leagueTable['deductions']as $deduction){
$output .="<li>". $deduction['team'].": -". $deduction['pts']." points (". $deduction['reason'].")</li>";}
$output .="</ul>";}return $output;}
add_shortcode('league_table','fetch_league_table');
This PHP file provides us with the table on the website, although I note that the year is 2019. I think this is because the Leaguetable API endpoint doesn't have a year integer. I have been told that I should be able to get the year integer from the Competitions endpoint. But I am not a PHP developer, and I think that the developer that gave me this code got it by going through an AI prompt (i.e. he doesn't know PHP either).
I can see the API endpoint in the code, so I would imagine that I copy that, paste it again but modify the URL and the queryparams to search for year. But what I don't know is how I would then put the query params together so that the table being displayed (compID 4) is for the current year (ex. 2024).
Would someone be able to assist me or point me in the right direction? I tried emailing the support email in the documentation but they have been less than helpful.
Question
Nick H. Supervisor
Hi all,
Please see the following documentation for reference: https://secure.rugby-league.com/api/docs/
A developer provided me with the following PHP file (although I have removed the API key and Secret):
This PHP file provides us with the table on the website, although I note that the year is 2019. I think this is because the Leaguetable API endpoint doesn't have a year integer. I have been told that I should be able to get the year integer from the Competitions endpoint. But I am not a PHP developer, and I think that the developer that gave me this code got it by going through an AI prompt (i.e. he doesn't know PHP either).
I can see the API endpoint in the code, so I would imagine that I copy that, paste it again but modify the URL and the queryparams to search for year. But what I don't know is how I would then put the query params together so that the table being displayed (compID 4) is for the current year (ex. 2024).
Would someone be able to assist me or point me in the right direction? I tried emailing the support email in the documentation but they have been less than helpful.
Many thanks in advance.
Link to comment
https://www.neowin.net/forum/topic/1449886-php-issues-displaying-a-league-table/Share on other sites
7 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now