I have a array that is dynamically generated and i am able to manipulate the data and print it in a table but I want to be able to print it differently.
This is what I have been able to do so far:
This is what I want to achieve
As you can see the array has multiple entries and for each entry I would like to create a new table and display the data like so:
There are some keys in the array I would prefer to leave out from being added to the table. the key names are: Id, CreatedDate, Incoming
Here is a short sample of what the array looks like:
[records] => Array
(
[0] => Array
(
[Id] =>
[CreatedDate] => 2016-02-18T02:24:57.000Z
[FromName] => Technical Support
[Incoming] =>
[MessageDate] => 2016-02-18T02:24:57.000Z
[Subject] => this is a test reply
[TextBody] => testt ref:_00D708cJQ._50080oYTuD:ref
[ToAddress] => [email protected]
)
[1] => Array
(
[Id] =>
[CreatedDate] => 2016-02-17T13:36:52.000Z
[FromName] => Technical Support
[Incoming] => 1
[MessageDate] => 2016-02-17T13:36:08.000Z
[Subject] => MySupport Portal: Test Email via API
[TextBody] => this is a test email 4 ref:_00D708cJQ._50080oYTuD:ref
[ToAddress] => [email protected]
)
Here is my current php code
$count = $response_array['size'] -1;
//print table headers
echo '<table border=1><tr>';
foreach( $response_array['records'][0] as $key => $value ) {
if($key !== 'Id') {
echo '<th>'.$key.'</th>';
}
}
echo '</tr><tr>';
//print table data
for ($i = 0; $i <= $count; $i++) {
foreach( $response_array['records'][$i] as $key => $value ) {
if($key !== 'Id') {
if($key === 'TextBody') {
echo '<td><pre>'.$value.'</pre></td>';
} else {
echo '<td>'.$value.'</td>';
}
}
}
echo '</tr><tr>';
}
echo "</tr></table>";
I know how to write the HTML but not sure how to tie in the php as im not sure how i can sort the headers to be in different part of the table.. in any case here is the html with dummy data as placeholders
<table border=1>
<tr>
<th>MessageDate</th>
<th>FromName</th>
<th>ToAddress</th>
</tr><tr>
<td>data</td>
<td>data</td>
<td>data</td>
</tr><tr>
<th colspan=3>Subject</th>
</tr><tr>
<td colspan=3>this is the subject</td>
</tr><tr>
<th colspan=3>TextBody</th>
</tr><tr>
<td colspan=3>this is the body</td>
</tr>
</table>

