i have the problem that it doesnt show me the matches correctly. It gives me the form-group class but shows no matches. Any ideas?
<form method="post">
<?php if (is_array($matches) && !empty($matches)): ?>
<?php foreach ($matches as $match): ?>
<div class="form-group">
<label>
<?php $match['Team1']['TeamName'] ?> vs <?php $match['Team2']['TeamName'] ?>
<input type="text" class="form-control" name="tips[<?= $match['MatchID'] ?>]" required>
</label>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No matches found.</p>
I have the api call here:
function getMatchData($season, $matchday) {
global $db;
$apiUrl = "https://www.openligadb.de/api/getmatchdata/bl1/$season/$matchday";
$matches = json_decode(file_get_contents($apiUrl), true);
foreach ($matches as $match) {
$db->insert('matches', [
'id' => $match['MatchID'],
'team1' => $match['Team1']['TeamName'],
'team2' => $match['Team2']['TeamName'],
'team1_goals' => $match['MatchResults'][0]['PointsTeam1'],
'team2_goals' => $match['MatchResults'][0]['PointsTeam2'],
'season' => $season,
'matchday' => $matchday
]);
}
return $matches;
EDIT: I found the solution myself: i’ve misspelled the array indexes like TeamName instead of teamName.
2
Answers
I found the solution myself: i've misspelled the array indexes like TeamName instead of teamName.
If your matches come from the database, they don’t follow the same format of the API. You then should:
#2. Don’t forget the
echo