title: Invalid JSON Response in Datatables
body: <p>I'm modifying the <code>jQuery Datatables</code>. All I want is to add <code>datepicker</code> for searching two dates but I got an error response, it says invalid <code>JSON</code>. Below is my code:</p>
  <pre><code>    $column = array('reciept_no','username','firstname','lastname','TotalQuantity','TotalPrice','date');
  
      $query = &quot;SELECT sales_product.reciept_no,sum(price) AS TotalPrice,sum(qty) AS TotalQuantity,username,date,customer.firstname,customer.lastname FROM sales_product JOIN sales ON sales_product.reciept_no=sales.reciept_no JOIN customer ON sales.customer_id = customer.customer_id GROUP BY reciept_no &quot;;
  
      if($_POST['is_date_search'] == &quot;yes&quot;){
          $query .= 'HAVING sales.date BETWEEN &quot;'.$_POST[&quot;start_date&quot;].'&quot; AND &quot;'.$_POST[&quot;end_date&quot;].'&quot;'; 
      }
  
      if (isset($_POST[&quot;search&quot;][&quot;value&quot;])) {
          $query .= '
              ( AND reciept_no LIKE &quot;%' .$_POST[&quot;search&quot;][&quot;value&quot;].'%&quot; 
              OR TotalPrice LIKE &quot;%' .$_POST[&quot;search&quot;][&quot;value&quot;].'%&quot;
              OR TotalQuantity LIKE &quot;%' .$_POST[&quot;search&quot;][&quot;value&quot;].'%&quot;
              OR username LIKE &quot;%' .$_POST[&quot;search&quot;][&quot;value&quot;].'%&quot;
              OR firstname LIKE &quot;%' .$_POST[&quot;search&quot;][&quot;value&quot;].'%&quot;
              OR lastname LIKE &quot;%' .$_POST[&quot;search&quot;][&quot;value&quot;]. '%&quot;)
          ';
      }
  
      if(isset($_POST['order'])){
          $query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
      }else{
          $query .= 'ORDER BY reciept_no DESC';
      }
  
      $query1 = '';
  
      if($_POST['length'] != -1){
          $query1 = 'LIMIT' .$_POST[&quot;start&quot;].','.$_POST[&quot;length&quot;];
      }
      $data = array();
  
      $result = mysqli_query($db, $query . $query1);
      $number_filter_row = mysqli_num_rows(mysqli_query($db, $query));
  
          while($row = mysqli_fetch_array($result)){
              $sub_array = array();
              $sub_array[] = $row[&quot;reciept_no&quot;];
              $sub_array[] = $row[&quot;username&quot;];
              $sub_array[] = $row[&quot;firstname&quot;];
              $sub_array[] = $row['lastname'];
              $sub_array[] = $row[&quot;TotalQuantity&quot;];
              $sub_array[] = $row[&quot;TotalPrice&quot;];
              $sub_array[] = $row[&quot;date&quot;];
              $data[] = $sub_array; 
          }
  function get_all_data($db){
          $query = &quot;SELECT sales_product.reciept_no,sum(price) AS TotalPrice,sum(qty) AS TotalQuantity,username,date,customer.firstname,customer.lastname FROM sales_product JOIN sales ON sales_product.reciept_no=sales.reciept_no JOIN customer ON sales.customer_id = customer.customer_id GROUP BY reciept_no&quot;;
          $result = mysqli_query($db, $query);
          return mysqli_num_rows($result);
      }
      $output = array(
          &quot;draw&quot;      =&gt; intval($_POST[&quot;draw&quot;]),
          &quot;recordsTotal&quot;  =&gt; get_all_data($db),
          &quot;recordsFiltered&quot; =&gt; $number_filter_row,
          &quot;data&quot;      =&gt; $data
      );
  
      echo json_encode($output);
  </code></pre>
  <p>The error says</p>
  <blockquote>
  <p>DataTables warning: table id=sales_table - Invalid JSON response. For more information about this error, please see <a href="http://datatables.net/tn/1" rel="nofollow noreferrer">http://datatables.net/tn/1</a></p>
  </blockquote>
  <p>I am referring to this site for my code and I'm just modifying it of what my systems need:
  <a href="https://www.webslesson.info/2017/06/date-range-search-in-datatables-using-php-ajax.html" rel="nofollow noreferrer">https://www.webslesson.info/2017/06/date-range-search-in-datatables-using-php-ajax.html</a></p>
  <p>I did search the problem, and found out that it will be fetch on developer tools and clicking on the network tab. I found this one</p>
  <blockquote>
  <p>Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in /opt/lampp/htdocs/PointOfSale/sales/fetch_all_data.php on line 38</p>
  <p>Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in /opt/lampp/htdocs/PointOfSale/sales/fetch_all_data.php on line 40
  {&quot;draw&quot;:1,&quot;recordsTotal&quot;:10,&quot;recordsFiltered&quot;:null,&quot;data&quot;:[]}</p>
  </blockquote>
  <p>I'd tried fixing my query but nothing happens.This type of query is new to me so its hard for me to site the problem. Can someone give me an idea or site what my code is lacking?</p>