kisham08 kisham08 - 3 years ago 114
JSON Question

Data is not showing

I am trying to display data from my database using bootstrap table, php and javascript. I have this code:

index.html

<div class="panel-body">
<div class="row">
<div class="col-md-12">
<table id="table"
data-show-columns="true"
data-height="500">
</table>
</div>
</div>
</div>


javascript

var $table = $('#table');
$table.bootstrapTable({
url: 'list-farmers.php',
search: true,
pagination: true,
buttonsClass: 'primary',
showFooter: true,
minimumCountColumns: 2,
columns: [{
field: 'landID',
title: 'ID',
sortable: true,
},{
field: 'location',
title: 'Location',
sortable: true,
},{
field: 'surf_area',
title: 'Surface Area',
sortable: true,

},{
field: 'surf_unit',
title: 'Unit',
sortable: true,

},{
field: 'ownership',
title: 'Ownership',
sortable: true,

},{
field: 'soiltype',
title: 'Soil Type',
sortable: true,
}, ],

});


php

include 'dbconnect.php';

$sqltran = mysqli_query($con, "SELECT * FROM land where farmerID = 8")or die(mysqli_error($con));
$arrVal = array();

$i=1;
while ($rowList = mysqli_fetch_array($sqltran)) {

$name = array(
'num' => $i,
'landID'=>$rowList['landID'],
'location'=> $rowList['location'],
'surf_area'=> $rowList['surf_area'],
'surf_unit'=> $rowList['surf_unit'],
'ownership'=> $rowList['ownership'],
'soiltype'=> $rowList['soiltype']
);


array_push($arrVal, $name);
$i++;
}
echo json_encode($arrVal);

mysqli_close($con);


There must be something wrong with the codes because when I run it, the table and the design is there, but there is no data.

This is the result of the code

This is the data in the database that should match.

enter image description here

Answer Source
  • If you are certain there's no error in your db-connect.php file. Your list-farmers.php looks good, but i suspect it's returning an html page.

Add this to your list-farmers.php, right after your opening tag

header('Content-Type: application/json');

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download