title: How to set column names in PHP/SQL generated .csv spreadsheet
body: <p>I found the following script on the web and edited it to my needs, but the one thing I'm not able to figure out is how to change the column names. AS-is, the column names show up in the spreadsheet as the name of the corresponding column in the database. is there a way to change this?</p>
  
  <p>thanks for any advice!
  here's my code:</p>
  
  <pre><code>&lt;?php
  $host = 'asdf';
  $user = 'asdf';
  $pass = 'asdf';
  $db = 'asdf';
  $table = 'stats';
  $file = 'export';
  
      $fields = "date, name, time, inbset, asapset, faxset, obset, totset, inbclo, asapclo, faxclo, obclo, totclo, inbtot, asaptot, faxtot, obtot, total, comments";
  
  $filename = $file."_".date("Y-m-d");
  
  $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
  mysql_select_db($db) or die("Can not connect.");
  
  $result = mysql_query("SHOW COLUMNS FROM ".$table."");
  $i = 0;
  if (mysql_num_rows($result) &gt; 0) {
  while ($row = mysql_fetch_assoc($result)) {
  $csv_output .= $row['Field'].", ";
  $i++;
  }
  }
  $csv_output .= "\n";
  
  $values = mysql_query("SELECT $fields FROM ".$table."");
  while ($rowr = mysql_fetch_row($values)) {
  for ($j=0;$j&lt;$i;$j++) {
  $csv_output .= $rowr[$j].", ";
  }
  $csv_output .= "\n";
  }
  
  $filename = $file."_".date("Y-m-d_H-i",time());
  header("Content-type: application/vnd.ms-excel");
  header("Content-disposition: csv" . date("Y-m-d") . ".csv");
  header( "Content-disposition: filename=".$filename.".csv");
  print $csv_output;
  exit;
  ?&gt;
  </code></pre>