i want to fetch data from mysql on basis of unique id. then display this data in bootstarp table.
$('#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
});
}
});
i have followed this example https://www.sourcecodesite.com/use-bootstrap-tables-display-data-mysql.html. but the problem is my data is not displaying. table is empty on loading
my php code that will display data
<?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);
}
?>
Try to edit your code like this:
var $table = $('#table1');
$table .bootstrapTable('load', obj1);
$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
});
}
});