Foreach com table

0

I'm creating a website that aims to show the games that are happening in the world in real time. I'm trying to make a for the table lines to be created "alone" according to the amount of games I will have at the moment I come from the API, I'm using the bet365 API. Attempt I made:

 <?php
  for(i=0;i<=$transaction['results'];i++){
  echo "<th></th>";
  }
 ?>

Here is a photo with the layout template:

Note:Iwantedthecolorstobeinterleavedalsoasshowninthephoto.

TodisplaytheresultsI'musingthefollowingcode:

foreach($transaction['results']as$element){echo$element['league']['name'].PHP_EOL;echo$element['home']['name'].PHP_EOL;echo$element['away']['name'].PHP_EOL;}

JSONmodelcomingfromtheAPI

{"success": 1,
   "pager": {
    "page": 1,
    "per_page": 1000,
    "total": 4
     },
     "results": [
     {
     "id": "77564080",
    "time": "1543528800",
    "time_status": "1",
    "league": {
        "id": "3024",
        "name": "Copa Libertadores - Feminino"
    },
    "home": {
        "id": "9105",
        "name": "EC Iranduba - Feminino"
    },
    "away": {
        "id": "170148",
        "name": "Atlético Huila - Feminino"
    },
    "ss": "1-0",
    "our_event_id": "1093051"
},
    
asked by anonymous 03.12.2018 / 12:25

1 answer

1

I do not understand what you can not do, I did a quick example similar to what you show, here an image showing the result. You will have to change the css to stay the way you do but the base is already done, besides adjust the name of the columns and print the right variables. If you have questions about tables, you can view here .

<table>
    <tr>
        <th>Coluna 1</th>
        <th>Coluna 2</th>
        <th>Coluna 3</th>
    </tr>
    <?php foreach ($json['results'] as $key => $element) { ?>
        <tr>
        <td><?php echo $element['league']['name'].'<br>'.$element['home']['name'].' X '.$element['away']['name']; ?></td>
        <td><?php echo $element['ss']; ?></td>
        <td><?php echo '00:00'; ?></td>
        </tr>
    <?php } ?>

</table>

<style>
table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
</style>
    
03.12.2018 / 19:25