• 0

My Data is not showing on my html page Pin


Question

<?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);

?>

// here second page///
&lt;html>
&lt;head>

&lt;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");
});
});
});

&lt;/script>

&lt;/head
&lt;body>
<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>


&lt;/body>
&lt;/html>

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I see you've got 2 pages.

-getjson.php

-Index.php(or whatever it's called) fetching the content of getjson.php

 

Does getjson.php show any results/errors when directly accesed?

 

If you can post both pages using the "<>" button or attach them I can look into the problem.

 

I didn't knew of $.getJSON by the way, I always used $.get instead :p

 

 

Link to comment
Share on other sites

This topic is now closed to further replies.