> http://www.devpapers.com/article/54
>
> google for PHP to CSV and there are a lot more hits
>
Here's what I found in page 13 of google's results. It produces a tab-delimited file.
<?php
include ("login.inc");
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$select = "SELECT * FROM $table ORDER BY Street, Num, Last ASC";
$export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) );
$fields = mysql_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysql_field_name( $export , $i ) . "\t";
}
while( $row = mysql_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "\t";
}
else
{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim( $line ) . "\n";
}
$data = "" "\r" , "" , $data );
if ( $data == "" )
{
$data = "" Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=FILENAME.XLS");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
Many thanks.
The php_mysql group is dedicated to learn more about the PHP/MySQL web database possibilities through group learning.
SPONSORED LINKS
| American general life and accident insurance company | American general life insurance company | American general life |
| American general mortgage | American general life insurance | Computer internet security |
YAHOO! GROUPS LINKS
- Visit your group "php_mysql" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
