Im having trouble creating a table out from this array:
http://pastebin.com/DXFjfhHJ
I started out with this:
<table style="width: 100%; text-align: center;">
<tr>
<td>Time</td>
<开发者_高级运维;td>Aktivitet</td>
<td>Duration</td>
<td>Metabolisation</td>
</tr>
then i did:
foreach{$training as $time => $metabolisation}{
?>
<tr style="text-align: left;">
<td><?php echo $time; ?></td>
<td>Activity name</td>
<td>Duration</td>
<td><?php echo $metabolisation; ?></td>
</tr>
<?php
}
Which works almost.. It shows the right $time ( 03:00 etc. ), but nothing in $metabolisation. And I dont know how to call the Activity, it should be the arrays "name" variable. Same with duration, it should be the arrays "duration"
How can I do this?
Well the structure your using in your pastebin is not compatible with your foreach. You realy need to look deeper in your array structure like this.
<?php foreach( $training as $time => $data ): ?>
<tr style="text-align: left;">
<td><?php echo $time; ?></td>
<td>Total <?php echo $data['entries'][0]['name']; ?></td>
<td>Duration <?php echo $data['entries'][0]['duration']; ?></td>
<td><?php echo $data['entries'][0]['metabolisation']; ?></td>
</tr>
<?php endforeach; ?>
foreach($training as $time => $metabolisation){
foreach($metabolisation['entries'] as $entry) {
?>
<tr style="text-align: left;">
<td><?php echo $time; ?></td>
<td><?php echo $entry['name']; ?></td>
<td><?php echo $entry['duartion']; ?></td>
<td><?php echo $entry['metabolisation']; ?></td>
</tr>
<?php
}
}
?>
It probably doesn't output the data in an appropriate form, but you get the idea how to access it.
精彩评论