引导表不显示数据

z18hc3ub  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(358)


我想根据唯一的id从mysql获取数据,然后在bootstarp表中显示这些数据。

  1. $('#Modal').modal('toggle');
  2. var row_id = $('#id').val();
  3. $.ajax ({
  4. url: "test.php",
  5. data: { id : row_id },
  6. method:"POST",
  7. //async: false,
  8. dataType:"json",
  9. success: function( result ) {
  10. var obj=result;
  11. var obj1=JSON.parse(obj);
  12. //table
  13. $('#table1').bootstrapTable('load', obj1);
  14. var $table = $('#table1');
  15. $table.bootstrapTable({
  16. search: true,
  17. pagination: true,
  18. buttonsClass: 'primary',
  19. showFooter: true,
  20. minimumCountColumns: 2,
  21. columns: [{
  22. field: 'num',
  23. title: 'ID'
  24. }, {
  25. field: 'first',
  26. title: 'firstname'
  27. }, {
  28. field: 'second',
  29. title: 'second Name'
  30. }, {
  31. field: 'three',
  32. title: 'last name'
  33. }, {
  34. field: 'four',
  35. title: 'father name'
  36. }, {
  37. field: 'five',
  38. title: 'Gender'
  39. }, {
  40. field: 'six',
  41. title: 'class'
  42. }, {
  43. field: 'seven',
  44. title: 'total marks'
  45. }, {
  46. field: 'last',
  47. title: 'percentage'
  48. }],
  49. data: obj
  50. });
  51. }
  52. });

我遵循了这个例子https://www.sourcecodesite.com/use-bootstrap-tables-display-data-mysql.html. 但问题是我的数据没有显示出来。加载时表为空
我的php代码将显示数据

  1. <?php
  2. //require 'db.php';
  3. $con = mysqli_connect("localhost","root","","test");
  4. if(isset($_POST['id']))
  5. {
  6. $sqltran = mysqli_query($con, "SELECT * FROM table WHERE id = '".$_POST['id']."'")or die(mysqli_error($con));
  7. $arrVal = array();
  8. $i=1;
  9. while ($rowList = mysqli_fetch_array($sqltran)) {
  10. $name = array(
  11. 'id' => $rowList['id'],
  12. 'first'=> $rowList['A'],
  13. 'second'=> $rowList['B'],
  14. 'three'=> $rowList['C'],
  15. 'four'=> $rowList['D'],
  16. 'five'=> $rowList['E'],
  17. 'six'=> $rowList['F'],
  18. 'seven'=> $rowList['G'],
  19. 'last'=> $rowList['H']
  20. );
  21. array_push($arrVal, $name);
  22. $i++;
  23. }
  24. echo json_encode($arrVal);
  25. mysqli_close($con);
  26. }
  27. ?>
gopyfrb3

gopyfrb31#

尝试如下编辑代码:

  1. var $table = $('#table1');
  2. $table .bootstrapTable('load', obj1);
  3. $table.bootstrapTable({
  4. search: true,
  5. pagination: true,
  6. buttonsClass: 'primary',
  7. showFooter: true,
  8. minimumCountColumns: 2,
  9. columns: [{
  10. field: 'num',
  11. title: 'ID'
  12. }, {
  13. field: 'first',
  14. title: 'firstname'
  15. }, {
  16. field: 'second',
  17. title: 'second Name'
  18. }, {
  19. field: 'three',
  20. title: 'last name'
  21. }, {
  22. field: 'four',
  23. title: 'father name'
  24. }, {
  25. field: 'five',
  26. title: 'Gender'
  27. }, {
  28. field: 'six',
  29. title: 'class'
  30. }, {
  31. field: 'seven',
  32. title: 'total marks'
  33. }, {
  34. field: 'last',
  35. title: 'percentage'
  36. }],
  37. data: obj
  38. });
  39. }
  40. });
展开查看全部

相关问题