我想根据唯一的id从mysql获取数据,然后在bootstarp表中显示这些数据。
$('#Modal').modal('toggle');
var row_id = $('#id').val();
$.ajax ({
url: "test.php",
data: { id : row_id },
method:"POST",
//async: false,
dataType:"json",
success: function( result ) {
var obj=result;
var obj1=JSON.parse(obj);
//table
$('#table1').bootstrapTable('load', obj1);
var $table = $('#table1');
$table.bootstrapTable({
search: true,
pagination: true,
buttonsClass: 'primary',
showFooter: true,
minimumCountColumns: 2,
columns: [{
field: 'num',
title: 'ID'
}, {
field: 'first',
title: 'firstname'
}, {
field: 'second',
title: 'second Name'
}, {
field: 'three',
title: 'last name'
}, {
field: 'four',
title: 'father name'
}, {
field: 'five',
title: 'Gender'
}, {
field: 'six',
title: 'class'
}, {
field: 'seven',
title: 'total marks'
}, {
field: 'last',
title: 'percentage'
}],
data: obj
});
}
});
我遵循了这个例子https://www.sourcecodesite.com/use-bootstrap-tables-display-data-mysql.html. 但问题是我的数据没有显示出来。加载时表为空
我的php代码将显示数据
<?php
//require 'db.php';
$con = mysqli_connect("localhost","root","","test");
if(isset($_POST['id']))
{
$sqltran = mysqli_query($con, "SELECT * FROM table WHERE id = '".$_POST['id']."'")or die(mysqli_error($con));
$arrVal = array();
$i=1;
while ($rowList = mysqli_fetch_array($sqltran)) {
$name = array(
'id' => $rowList['id'],
'first'=> $rowList['A'],
'second'=> $rowList['B'],
'three'=> $rowList['C'],
'four'=> $rowList['D'],
'five'=> $rowList['E'],
'six'=> $rowList['F'],
'seven'=> $rowList['G'],
'last'=> $rowList['H']
);
array_push($arrVal, $name);
$i++;
}
echo json_encode($arrVal);
mysqli_close($con);
}
?>
1条答案
按热度按时间gopyfrb31#
尝试如下编辑代码: