title: html table to CSV or Excel
body: <p>Alright, I'm starting to go a little crazy...</p>
  
  <p><a href="https://stackoverflow.com/questions/921037/jquery-table-to-csv-export">jQuery Table to CSV export</a></p>
  
  <p>I'm looking at that thread.</p>
  
  <p>It does work, but the output does everything by each LINE not by the HTML table rows.  For example, I have an address that is in one HTML cell:</p>
  
  <pre><code>1234 Berryman Lane
  Atlanta, GA 12345
  Unit # 54A
  </code></pre>
  
  <p>That will be THREE rows when it outputs to excel, instead of one cell, with returns in it.</p>
  
  <p>Further, there's no way to strip out the HTML that is inside of the HTML cells with that solution, as far as I know...</p>
  
  <p>Finally, Excel gives a warning when opening that file.  </p>
  
  <hr>
  
  <p>What I'm getting at, is that I'd rather just have something that can take the inner most data in the HTML cells (not including HTML inside of a cell), and rip it to CSV.    Is there anything that does this well these days?</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Well, I just found the best thing yet, this is pretty perfect:</p>
  
  <pre><code>$table = 'myTable';
  $file = 'exportFile';
  
  $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 * 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;
  </code></pre>
  
  <p>I think this is my keeper.  It goes to a CSV file with no issues, loads in Excel with no issues, it's my dream come true!</p>