At 21:33 16-6-2003, you wrote:
I see all the options in phpMyAdmin for CSV/excel
output but I can't get it to export the fieldnames,
headers as well.

It'd be nice to have it automatically do that into
excel so the output is easier to follow and provide to
someone else.

Am I just missing the option in phpMyAdmin or does it
not output the fieldnames into CSV/excel?

There are quite some choices in phpMyAdmin, i did not check but they are pretty self explanatory.


I wrote myself a script that, when linked from a browser, returns a csv file. I still have some problems with the delimitations in some version of Excel and with opening it from Mozille Firebird, but you may like it. If all data ends op in row A of Excel, the field delimiter goes wrong.

------------------------
(a)nticopyright 2003 Chris - as many examples over the net inspired me (but i did not particularly copy any of them)
------------------------
<?PHP


//*--------------------------------*//
//* QUERY PART *//
//*--------------------------------*//
include('config.php'); // with $config array containing host etc.
mysql_connect($config['dbhost'], $config['dbuname'], $config['dbpass']);
mysql_select_db($config['dbname']) or die ("<br><font color=\"red\">Unable to select database.</font>");


$query="SELECT time, Titles,Initials,First_Name,Family_Name,Institute,E_mail,Telephone FROM SYMP2003 ORDER BY time";

// query depends on url variable 'n':
if ($_GET['n']==2) $query="SELECT time, Titles, Initials, First_Name,Family_Name,Position,SENSE_Institute,Address,E_mail,Telephone,Fax FROM SYMP2003 ";
if ($_GET['n']==3) $query="SELECT * FROM SYMP2003 ";


$result=mysql_query($query) or die (mysql_error());

//*--------------------------------*//
//* BUILD DATA PART *//
//*--------------------------------*//
$string_csv='';
while ($myrow = mysql_fetch_array($result,MYSQL_ASSOC))
{ foreach ($myrow as $value) {$string_csv .= "\"".str_replace('"',"''",str_replace("\r",'',$value))."\",";}
$string_csv .= "\n"; // line end
}


//*--------------------------------*//
//*     SEND AS FILE    *//
//*--------------------------------*//

if (strstr($_SERVER["HTTP_USER_AGENT"],"MSIE 5.5")) {$att = "";} else {$att = " attachment;";}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0


header("Content-type: text/csv");
header('Content-Disposition: inline; filename="MyFileName.csv"');

echo $string_csv;
exit;
?>





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to