Hey, so i am learning how to work with APIs and PHP just for fun.
I have a small web app using HTML, PHP and MAMP.
I have Soccer data displayed in a table on a page called "liveScores.php" with a unique ID for each game. When I click this link it opens a new page ("gameInfo.php") where i would like to delve deeper into the API for that game. However it is not working. It only works when I hardcode the ID but of course thats a waste of time as the IDs for each game changes. The id is correctly passed through my url but its just i do not know how to pull the data from it.
*UPDATE
When i click the link of the id it directs me to the new page. But no data is displayed.
Its simply an empty table with only the column names displayed.
When I run it through postman its the same.
Hardcode the ID in and i get data in both.
1. My method
===============
public function getMatchInfo() {
$url = $this->buildUrl('scores/events.json?
key=Ka88B6jZrxO8dDQt&secret=L233yXpNCWQDZyxJIGSkNbjeI8nWLdqw&id='
.$id);
return $this->makeRequest($url);
}
2. My HTML for the GameData Screen
=================
<?php foreach ($data['data']['event'] as $_event){ ?>
<tr>
<td style="text-align: center;"><?= $_event['id'] ?></td>
<td style="text-align: center;"><?= $_event['player'] ?></td>
</tr>
<?php } ?>
<tr>
3. The API itself
========================
{
"success": true,
"data": {
"event": [
{
"id": "10509914",
"match_id": "129180",
"player": "DEENEY TROY",
"time": "5",
"event": "GOAL",
"sort": "0",
"home_away": "h"
},
{
"id": "10509915",
"match_id": "129180",
"player": "MARIAPPA ADRIAN",
"time": "13",
"event": "YELLOW_CARD",
"sort": "1",
"home_away": "h"
},
What I have tried:
If i hard code the id in it works fine for that particular row of data. So i presume my issue lies in the "GameInfo" screen as although the ID is there in the URL it is not able to pull the correct info.