2017-07-24 110 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語句..