Converting json data to an HTML table

Posted by dnaluz on Stack Overflow See other posts from Stack Overflow or by dnaluz
Published on 2010-06-10T17:32:22Z Indexed on 2010/06/10 18:13 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery