数据不显示
Data is not showing
我正在尝试使用 bootstrap table、php 和 javascript 显示我的数据库中的数据。我有这个代码:
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);
代码一定有问题,因为当我 运行 它时,table 和设计在那里,但没有数据。
这是数据库中应该匹配的数据。
- 如果您确定 db-connect.php 文件中没有错误。
您的列表-farmers.php 看起来不错,但我怀疑它返回的是 html 页面。
将此添加到您的列表中-farmers.php,就在您的开始标记之后
header('Content-Type: application/json');
希望对您有所帮助。
是的!我找到原因了,
正如大家所说,MIME_TYPE是application/html。所以我把
header('Content-Type: application/json');
我的 dbconnect.php 是这样的:
$user = 'root';
$pass = '';
$db = 'farmingportal';
$con = mysqli_connect('localhost', $user, $pass, $db);
if($con){
echo 'success!';
}else {
echo 'not successful';
}
所以我只是删除了 if 语句..
我正在尝试使用 bootstrap table、php 和 javascript 显示我的数据库中的数据。我有这个代码:
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);
代码一定有问题,因为当我 运行 它时,table 和设计在那里,但没有数据。
这是数据库中应该匹配的数据。
- 如果您确定 db-connect.php 文件中没有错误。 您的列表-farmers.php 看起来不错,但我怀疑它返回的是 html 页面。
将此添加到您的列表中-farmers.php,就在您的开始标记之后
header('Content-Type: application/json');
希望对您有所帮助。
是的!我找到原因了,
正如大家所说,MIME_TYPE是application/html。所以我把 header('Content-Type: application/json');
我的 dbconnect.php 是这样的:
$user = 'root'; $pass = ''; $db = 'farmingportal'; $con = mysqli_connect('localhost', $user, $pass, $db); if($con){ echo 'success!'; }else { echo 'not successful'; }
所以我只是删除了 if 语句..