Something like this should work. Took it from an existing setup I was using, removed the logic that specified some control over which rows were sent so it sends everything matching your query. Note that mysql_* functions are on the way out and should be replaced with PDO object calls instead.... If you can send me a mysql_dump of the table and the query you'd want to use (assuming you just don't want everything) and I'll do it up and debug it, then send you back the known-good PHP. Email it to me - sj at gruv dot org
PHP Code:
<?php
// written by id10t licensed under the GPLv2
// should be updated to use PDO
// the query your csv file will be based on
$query="select foo,bar,bee from somedbtable";
// what database is your table stored in
$dbName="your-database-name";
// your database host - get from ISP or your geek
$hostname="mysqlserver.example.com";
// db user credentials - get from ISP or your geek
$username="dbuser";
$password="secretwords";
// nothing to edit below this line ... unless you want to
// send response headers to the browser
header( 'Content-Type: text/csv' );
header( 'Content-Disposition: attachment;filename=SMART.csv');
$fp = fopen('php://output', 'w');
MYSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mysql_select_db($dbName) or DIE("DB unavailable");
$result = mysql_query($query) or die($query);
$number = mysql_num_rows($result);
// output header row (if at least one row exists)
$row = mysql_fetch_assoc($result);
if($row) {
fputcsv($fp, array_keys($row));
// reset pointer back to beginning
mysql_data_seek($result, 0);
}
for($i=0;$i<$number;$i++){
$row = mysql_fetch_row($result);
fputcsv($fp, $row);
}
mysql_close();
fclose($fp);
?>