Click here to Skip to main content
15,898,832 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
<?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);

?>

///////// my html page where i want to show the data //////
XML
<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>
Posted
Comments
Suvendu Shekhar Giri 29-Jul-15 0:55am    
Are you getting any error or it runs fine but without showing data?
Salman _Memon 29-Jul-15 1:00am    
it run fine but not shwing data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900