Converting json data to an HTML table
- by dnaluz
I have an array of data in php and I need to display this data in a HTML table. Here is what an example data set looks like.
Array(
Array
(
[comparisonFeatureId] => 1182
[comparisonFeatureType] => Category
[comparisonValues] => Array
(
[0] => Not Available
[1] => Standard
[2] => Not Available
[3] => Not Available
)
[featureDescription] => Rear Seat Heat Ducts
),)
The dataset is a comparison of 3 items (shown in the comparisonValues index of the array)
In the end I need the row to look similar to this
<tr class="alt2 section_1">
<td><strong>$record['featureDescription']</strong></td>
<td>$record['comparisonValues'][0]</td>
<td>$record['comparisonValues'][1]</td>
<td>$record['comparisonValues'][2]</td>
<td>$record['comparisonValues'][3]</td>
</tr>
The problem I am coming across is how to best do this. Should I create the entire table HTML on the server side pass it over an ajax call and just dump pre-rendered HTML data into a div or pass the json data and render the table client side.
Any elegant suggestions?
Thanks in advanced.