RE: [PHP] export data to text file

From: Date: Sat, 28 Sep 2002 19:35:54 +0000
Subject: RE: [PHP] export data to text file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-117974@lists.php.net to get a copy of this message
> okay, how can I write a file in csv format either to the browser or to the > server? If I use the Mysqladmin page I get all the fields, I just want > some > of them. > Diana You can use the SELECT ... INTO OUTFILE query like someone else mentioned, and then use passthru() to send the file to the browser. It'll come out as text to the user and appear in the browser. If you want it available to download, then you'll have to send attachment headers before passthru(). If you don't have FILE privs so you can use the above query, then you could do something like this: $result = mysql_query("SELECT ... FROM table WHERE ... "); while($row = mysql_fetch_row($result)) { echo implode(",",$row); } You can use \t instead of , or whatever. That doesn't put quotes around strings or anything like that, though... ---John Holmes...

« previous php.general (#117974) next »