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
(
[compar
dnaluz,
as mentioned by others, there are great libs out there to do thios client side. I'd also take the stance that you'd be best sending the json array to the client and then using the lib to present the data in tabular format.
Altho i mention the use of nice presentation libs to create the table, below is a little function that i use for lightweight quick and dirty table visualizations from a json array:
function CreateTableFromJson(objArray) {
// has passed in array has already been deserialized
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
str = '';
str += '';
for (var index in array[0]) {
str += '' + index + ' ';
}
str += ' ';
str += '';
for (var i = 0; i < array.length; i++) {
str += (i % 2 == 0) ? '' : ' ';
for (var index in array[i]) {
str += '' + array[i][index] + ' ';
}
str += ' ';
}
str += ''
str += '
';
return str;
}
hope this is useful in some minor way.. jim
[edit] - here's a link to a page using a very similar technique: http://www.zachhunter.com/2010/04/json-objects-to-html-table/