skip to Main Content

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


  1. Chosen as BEST ANSWER

    I found the solution myself: i've misspelled the array indexes like TeamName instead of teamName.


  2. 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

    <form method="post">
    <?php if (is_array($matches) && !empty($matches)): ?>
          <?php foreach ($matches as $match): ?>
          <div class="form-group">
          <label>
          <?php echo $match['team1'] ?> vs <?php echo $match['team2'] ?>
          <input type="text" class="form-control" name="tips[<? echo  $match['id'] ?>]" required>
          </label>
          </div>
          <?php endforeach; ?>
    <?php else: ?>
          <p>No matches found.</p>
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search