I need some help with my code, I am noob with JSON and PHP, but I`m learning
[
{
"eventId": 213,
"balls": [
{
"ball": 26,
"id": 1
},
{
"ball": 31,
"id": 2
}
]
},
{
"eventId": 212,
"balls": [
{
"ball": 22,
"id": 1
},
{
"ball": 33,
"id": 2
}
]
}
]
I have this JSON and this part of php code:
<table>
<?php
$url = 'external-link';
$data = file_get_contents($url);
$json_post = json_decode($data,true);
?>
<table>
<tbody>
<?php foreach ($json_post as $event) : ?>
<tr>
<td><?php echo $event['eventId']; ?></td>
<td><?php foreach ($json_post as $ball) : ?> <?php echo $ball['balls'][0]['ball']; ?> <?php endforeach; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
I have a wrong display of this code, but not how I want to be:
213 | 26 31
212 | 22 33
Any help would be appreciated,thanks