The below is the file to show data retrieved from database using php.
<table class="mGrid" id="jsondata">
<thead>
<th>rollno</th>
<th>student name</th>
<th>branch</th>
</thead>
<tbody></tbody>
</table>
</div>
<script type="text/javascript">
$(document).ready(function(){
var url="getjson.php";
$("#jsondata tbody").html("");
$.getJSON(url,function(data){
$.each(data.users, function(i,user){
var newRow =
"<tr>"
+"<td>"+user.rollno+"</td>"
+"<td>"+user.stuname+"</td>"
+"<td>"+user.branch+"</td>"
+"</tr>" ;
$(newRow).appendTo("#jsondata tbody");
});
});
});
</script>
<p style="text-align: justify;">
The code for fetching data from mysql
</p>
<?php
$mysql_db_hostname = "localhost";
$mysql_db_user = "root";
$mysql_db_password = "neel";
$mysql_db_database = "sitams";
$con = @mysqli_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password,
$mysql_db_database);
if (!$con) {
trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}
$var = array();
$sql = "SELECT rollno,stuname,branch FROM studet where year='i' and academic='2014-2015'";
$result = mysqli_query($con, $sql);
while($obj = mysqli_fetch_object($result)) {
$var[] = $obj;
}
echo '{"users":'.json_encode($var).'}';
?>
<p style="text-align: justify;">
I can see the results in getjson.php but could not able to see showjson.html what is the reason.
Have you tried to validate the json provided by your page with an online service ? (jsonlint, jsonparser, and son on ??)
If your JSON is not valid, you won't be able to decode it.
Furthermore, can you access the data from
$.getJSON(url,function(data)
in your browser console.
My guess is you have a problem in this json.
HTH