开发者

populate html table with json values

I have an table.html, data.php and json.csv within the same folder.

data.php is doing fopen("json.csv","r") to read from json.csv.

How can I display the json objects as a table within table.html?

    <html>
    <head>
    <script type="text/javascript" src="jquery.js">
    function display(){
  $.post('data.php',function(data){
     $("#txtJSON").html(data); 
  });
    }

   </script>
   </head>
   <body onload="display()">
   <table id="#jobtable">
   <input type="text" id="txtJSON" /&g开发者_开发问答t;
   </table>
   </body>
   </html>


psuedocode

php

Take the data read in from doing the fopen.
create a php array (a1)
create a php array (a2)
split it on new lines 
iterate through all of those lines
  clear (a2)
  split the current line on commas (or w/e separator)
    insert each element into a2
  insert a2 into a1

return a json_encode(a1)

html

do a jQuery.parseJSON(returned data from php) http://api.jquery.com/jQuery.parseJSON/
iterate through the datastructure adding a new html row for every row in the structure...


you can convert json.csv output in a php array and merge data.php & table.html in one php file in that file make a html table with foreach


You will be better off if you use JavaScript for any extensive DOM manipulation. More specifically, jQuery plugin JSON-to-table can do exactly what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜