View Single Post
Old 06-23-2008, 03:45 PM   #2 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Why not do it to CSV, tested and this works for Open Office so it should work for excel (but microsoft being evil, it probably wont), there are also some bits of incorrect code within your example which i have fixed in mine:
PHP Code:
$conn mysql_connect($local,$user,$pass) or die ("Unable to connect to database.");

mysql_select_db($db$conn);

$result mysql_query("SELECT * FROM users") or die('Error, query failed');
$csv '';
$fileName 'test.csv';
while(
$row mysql_fetch_array($result))
{
    
$csv .= implode($row',')."\n";
}

header("Content-Type: text/comma-separated-values");
header("Content-Disposition: attachment; filename=$filename");
echo 
$csv
Hopefully that will give you what you need to get going.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 06-24-2008 at 09:22 AM. Reason: removed 'var_dump' left it in by accident when testing
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
sharma.9.pooja (06-24-2008)