title: Create a tsv file from MySQL table. Add more imaginary headers
body: <p>I have a MySQL table, from which I create tsv and csv files. I want to create the tsv file whilst adding imaginary headers to the file. I already use the MySQL column headers as the headers for the file, but I need to add extra imaginary headers not in the MySQL table. My current code creates the file, but I do not know how to go about adding the imaginary headers.</p>
  
  <p>It outputs</p>
  
  <pre><code>name    age address
  Daniel  24  Carlifornia
  Jane    22  New York
  </code></pre>
  
  <p>I want to output</p>
  
  <pre><code>name    age address option1 option2
  Daniel  24  Carlifornia anything    anything
  Jane    22  New York    anything    anything
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code>@chmod($export_tsv, 0777);
  $fe = @fopen($export_tsv."/export.tsv", "w+");
  if($fe){           
      $somecontent = "";
      //$somecontent = "header('Content-type: text/html; charset=utf-8')";
      $fields_count = 0;
  
      // fields headers
      $db-&gt;query($sql_view);
      if($row = $db-&gt;fetchAssoc()){
          foreach($row as $key =&gt; $val){
              if($fields_count++ &gt; 0) $somecontent .= "\t";
              // mysql column headers here
              $somecontent .= $key;
          }
      }
      $somecontent .= "\r\n"; 
  
      $db-&gt;query($sql_view);
      while($row = $db-&gt;fetchAssoc()){
          $fields_count = 0;
          foreach($row as $key =&gt; $val){
              if($fields_count++ &gt; 0) $somecontent .= "\t";
              //my own special code start
              $val = str_replace("\n","", $val);
              $val = str_replace("\r","", $val);
              $val = str_replace("\t","", $val);
  
              $val = stripslashes($val);                    
              $val = str_replace("chr(13)","", $val);
              //my own special code end
  
              $somecontent .= $val;              
          }
          $somecontent .= "\r\n"; 
      }
      utf8_encode($somecontent);
      $somecontent = mb_convert_encoding($somecontent, 'HTML-ENTITIES', "UTF-8");
  
      // write some content to the opened file.
     if (fwrite($fe, utf8_encode($somecontent)) == FALSE)
         echo 'file_writing_error'." (export.tsv)"; 
     fclose($fe);           
  }
  </code></pre>