2017-07-24 128 views
3

我想从我的数据库使用引导表,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); 

一定有什么错误的代码,因为当我运行它时,表和设计在那里,但没有数据。

This is the result of the code

这是应该匹配数据库中的数据。

enter image description here

+0

你肯定有任何匹配的数据库中的数据? – Qirel

+0

是的,有一场比赛。此外,我试图从陆地表中选择所有的数据,但它仍然不显示。 – kisham08

+1

尝试在浏览器上使用开发工具来查看list-farmers.php是否正确地返回应用程序/ json的MIME_TYPE而不是application/html – Oluwaseye

回答

2
  • 如果你一定有你的DB-connect.php文件中没有任何错误。 您的列表 - farmers.php看起来不错,但我怀疑它是返回一个html页面。

添加到您的列表farmers.php,你打开标签

header('Content-Type: application/json'); 

希望这有助于之后。

0

是的!我发现原因,

  1. 正如你们都说过的,MIME_TYPE是application/html。所以我把 头('Content-Type:application/json');

  2. 而且我dbconnect.php是这样的:

    $user = 'root'; 
    $pass = ''; 
    $db = 'farmingportal'; 
    $con = mysqli_connect('localhost', $user, $pass, $db); 
    if($con){ 
        echo 'success!'; 
    }else { 
        echo 'not successful'; 
    } 
    

所以我刚才删除的if语句..