引导表不显示数据

时间:2018-10-05 12:06:44

标签: mysql bootstrap-table

enter image description here我想基于唯一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 个答案:

答案 0 :(得分:1)

尝试像这样编辑代码:

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
});
            }

        });