No data displayed

I am trying to display data from my database using bootstrap table, php and javascript. I have this code:

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

      

There must be something wrong in the code, because when I run it, the table and design is there, but no data.

This is the result of the code

This is the data in the database that must match.

enter image description here

+3


source to share


2 answers


  • If you are sure there is no error in your db-connect.php file . Your list-farm.php looks good, but I suspect it is returning an html page.

Add this to your list-farm.php, right after your open tag



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

      

Hope it helps.

+2


source


YES! I found out the reason

  • As you all said, the MIME_TYPE is application / html. So I put header ('Content-Type: application / json');

  • And my dbconnect.php was like this:

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



so I just removed the if statement.

0


source







All Articles