title: CodeIgniter: Export data from database into excel and download
body: <p>I'm working on a project, that requires exporting data from MYSQL DB depending on the multiple conditions. I am referring <a href="http://only4ututorials.blogspot.in/2016/05/how-to-export-to-excel-in-codeigniter-3.html" rel="nofollow">this</a>:</p>
  
  <p>This is my source code:</p>
  
  <pre><code>public function exportExcelData($records)
  {
    $heading = false;
          if (!empty($records))
              foreach ($records as $row) {
                  if (!$heading) {
                      // display field/column names as a first row
                      echo implode("\t", array_keys($row)) . "\n";
                      $heading = true;
                  }
                  echo implode("\t", ($row)) . "\n";
              }
   }
  
  public function fetchDataFromTable()
  {
       $query =$this-&gt;db-&gt;get('one_piece_characters'); // fetch Data from table
       $allData = $query-&gt;result_array();  // this will return all data into array
       $dataToExports = [];
       foreach ($allData as $data) {
          $arrangeData['Charater Name'] = $data['name'];
          $arrangeData['Charater Profile'] = $data['profile'];
          $arrangeData['Charater Desc'] = $data['description'];
          $dataToExports[] = $arrangeData;
    }
    // set header
    $filename = "dataToExport.xls";
                  header("Content-Type: application/vnd.ms-excel");
                  header("Content-Disposition: attachment; filename=\"$filename\"");
    $this-&gt;exportExcelData($dataToExports);
   }
  </code></pre>
  
  <p>If I use it without any where clause, it is giving entire table.</p>
  
  <p>If i use only single where clause, it works good.</p>
  
  <p>Bur, if I use multiple where conditions. it gives me a blank excel sheet.</p>
  
  <p>Does anyone have any idea regarding how to make it work with multiple where conditions?</p>