<?php mysql_connect ("localhost", "root", "") or die (mysql_error()); mysql_select_db ("webservices_exmple")or die (mysql_error()); $var = array(); $sql = "SELECT * FROM User"; $result = mysql_query($sql); while($obj = mysql_fetch_object($result)) { $var[] = $obj; } echo json_encode($var); ?>
<html> <head> <script type="text/javascript"> $(document).ready(function(){ var url="getjson.php"; $("#jsondata tbody").html(""); $.getJSON(url,function(data){ $.each(data.User,function(i,data){ var newRow = "<tr>" +"<td>"+data.id+"</td>" +"<td>"+data.name+"</td>" +"<td>"+data.age+"</td>" +"<td>"+data.gender+"</td>" +"</tr>" ; $(newRow).appendTo("#jsondata tbody"); }); }); }); </script> </head <body> </body> </html> <table class="mGrid" id="jsondata" > <thead> <th>Id</th> <th>Name</th> <th>Age</th> <th>Gender</th> <th>Location</th> </thead> <tbody></tbody> </table>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)