title: How to populate Jquery datatable with data retrieved from mysql?
body: <p>I am trying to populate datatable on some button click with data from the database.  </p>
  
  <p>However the following code is <strong>working [using text file]</strong>  </p>
  
  <pre><code>-----Javascript:-----
  
  $('#tblData').dataTable( {
      "bProcessing": true,
      "sAjaxSource": 'data.txt'
  } );
  
  -----data.txt-----
  
  {
  "aaData": [
   [
     "row 1 col 1 data",
     "row 1 col 2 data",
     "row 1 col 3 data",
     "row 1 col 4 data"
   ],
   [
     "row 2 col 1 data",
     "row 2 col 2 data",
     "row 2 col 3 data",
     "row 2 col 4 data"
   ],
   [
     "row 3 col 1 data",
     "row 3 col 2 data",
     "row 3 col 3 data",
     "row 3 col 4 data"
   ]
   ]
  }
  </code></pre>
  
  <p>How to pass such data fom php ??<br>
  The following code is <strong>not working [using php/mysql]</strong></p>
  
  <pre><code>-----Javascript-----
  
  $('#tblData').dataTable( {
      "bProcessing": true,
      "sAjaxSource": 'response.php'
  } );  
  
  
  ------response.php------
  
  include_once("config.php");
  $dataArr = array();
  $query = "SELECT data1,data2,data3,data4 from tbl_data";
  $result = $conn-&gt;query($query);
  $result-&gt;data_seek(0);
  while($row = $result-&gt;fetch_array(MYSQLI_ASSOC)){
  $ dataArr [] = $row;   // ?? What to do here?
  }
  echo json_encode($dataArr);  
  </code></pre>
  
  <p><strong>how to make it working ??</strong></p>