Re: [PHP-DB] csv export...?
Andre, et al -- [Sorry for the delay...] ...and then Andre Speelmans said... % % Hi David, Hi! % % On Fri, Jan 09, 2004 at 11:04:21AM -0500, David T-G wrote: % %header (Content-Type: application/csv;) ; # this is a CSV %header (Content-disposition: attachment; filename=authorized-visitors.$d.csv) ; # file name %... % [suck in file and dump into $a array] % foreach ( array_keys($a) as $ak ) # walk thru the array %{ print \$a[$ak]\, ; }# print the field (yes, even if blank) % % But this would go wrong if $a[$ak] contained a double quote. Remember you have Oooh; good point. My input is all sanitized, so becoamse quot; and so on, but for raw data that would definitely be a factor. % to escape those characters. Can't the database of OP do a dump, like MySQL % can? Well, in my case each record is a file on disk, so that doesn't apply. Thanks HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP-DB] csv export...?
Hi David, On Fri, Jan 09, 2004 at 11:04:21AM -0500, David T-G wrote: Tristan -- % Now I have found loadsa sites that let me upload a csv file, but not the % other way around... You might check PHPClasses to see if anyone has done this; I wouldn't be surprised. In general, though, you declare the file type and then run through a loop. From some code I have: header (Content-Type: application/csv;) ; # this is a CSV header (Content-disposition: attachment; filename=authorized-visitors.$d.csv) ; # file name ... [suck in file and dump into $a array] foreach ( array_keys($a) as $ak ) # walk thru the array { print \$a[$ak]\, ; } # print the field (yes, even if blank) But this would go wrong if $a[$ak] contained a double quote. Remember you have to escape those characters. Can't the database of OP do a dump, like MySQL can? [ rest of script stripped ] -- Regards, Andre -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] csv export...?
You didn't try to hard isn't it! :) If you want to save a file as csv just save the vars like this 1,2,3 4,5,6 ... 0,0,0 If you want to link a csv file for download put a href='file.csv'download/a. It's not so hard after all. :) Or I didn't get your message. Anyway, good luck! - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, January 09, 2004 17:35 Subject: [PHP-DB] csv export...? Google is not my friend today... I have a reportng tool on a database i have, and I want to be able to exort the selected results (I've saved the SQL query as a session variable for ease of use) and save that data as a csv file... with headers if possible... Now I have found loadsa sites that let me upload a csv file, but not the other way around... Anyone care to help? * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] csv export...?
Cheers for prompt reply... But.. what? I need to take an SQL query, and export teh results to a csv file... Are you really sure that simply pointing to a non existant csv file does that? I don't see it somehow...? I'm sorry if I'm wrong... Viorel Dragomir [EMAIL PROTECTED] 09/01/2004 15:50 To [EMAIL PROTECTED], [EMAIL PROTECTED] cc Subject Re: [PHP-DB] csv export...? You didn't try to hard isn't it! :) If you want to save a file as csv just save the vars like this 1,2,3 4,5,6 ... 0,0,0 If you want to link a csv file for download put a href='file.csv'download/a. It's not so hard after all. :) Or I didn't get your message. Anyway, good luck! - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, January 09, 2004 17:35 Subject: [PHP-DB] csv export...? Google is not my friend today... I have a reportng tool on a database i have, and I want to be able to exort the selected results (I've saved the SQL query as a session variable for ease of use) and save that data as a csv file... with headers if possible... Now I have found loadsa sites that let me upload a csv file, but not the other way around... Anyone care to help? * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. ***
Re: [PHP-DB] csv export...?
Tristan -- ...and then [EMAIL PROTECTED] said... % % Google is not my friend today... ... % Now I have found loadsa sites that let me upload a csv file, but not the % other way around... You might check PHPClasses to see if anyone has done this; I wouldn't be surprised. In general, though, you declare the file type and then run through a loop. From some code I have: header (Content-Type: application/csv;) ; # this is a CSV header (Content-disposition: attachment; filename=authorized-visitors.$d.csv) ; # file name ... [suck in file and dump into $a array] foreach ( array_keys($a) as $ak ) # walk thru the array { print \$a[$ak]\, ; }# print the field (yes, even if blank) print \n ;# end the row $total[$d]++ ; # keep count } # if($age||$ftime) // }}} } # if(is_file) } # while(readdir)// }}} % % Anyone care to help? There ya go :-) HTH HAND Happy New Year :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP-DB] csv export...?
It looks like is not so simple. But is not difficult at all.. Try to make something like: ?php header(Content-type: text/csv); $query = SELECT * FROM tables; $result = mysql_query($query); while($row = mysql_fetch_row($result)){ print implode(,, $row); } mysql_free_result($result); ? Check if functions like implode has the correct arguments. Anyway hopes it gives you a clue about what is going on. Don't forget to connect to database first of all. - Original Message - From: [EMAIL PROTECTED] To: Viorel Dragomir [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, January 09, 2004 17:52 Subject: Re: [PHP-DB] csv export...? Cheers for prompt reply... But.. what? I need to take an SQL query, and export teh results to a csv file... Are you really sure that simply pointing to a non existant csv file does that? I don't see it somehow...? I'm sorry if I'm wrong... Viorel Dragomir [EMAIL PROTECTED] 09/01/2004 15:50 To [EMAIL PROTECTED], [EMAIL PROTECTED] cc Subject Re: [PHP-DB] csv export...? You didn't try to hard isn't it! :) If you want to save a file as csv just save the vars like this 1,2,3 4,5,6 ... 0,0,0 If you want to link a csv file for download put a href='file.csv'download/a. It's not so hard after all. :) Or I didn't get your message. Anyway, good luck! - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, January 09, 2004 17:35 Subject: [PHP-DB] csv export...? Google is not my friend today... I have a reportng tool on a database i have, and I want to be able to exort the selected results (I've saved the SQL query as a session variable for ease of use) and save that data as a csv file... with headers if possible... Now I have found loadsa sites that let me upload a csv file, but not the other way around... Anyone care to help? * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] csv export...?
Viorel, et al -- ...and then Viorel Dragomir said... % % It looks like is not so simple. But is not difficult at all.. Right. % ... % while($row = mysql_fetch_row($result)){ % print implode(,, $row); I agree that implode is a better way to go. I had to have my fields export in a particular order when they were stored differently, so I loop through my format array to get the order of the keys to pull from the data array. HTH HAND HNY :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP-DB] csv export...?
Getting there... That did indeed output my results to the screen... Next steo is to output that same data to a new file... I've done downloads on my site elsewhere, using header(), but with existing files... I guess I need to learn how to use fwrite? Viorel Dragomir [EMAIL PROTECTED] 09/01/2004 16:09 To [EMAIL PROTECTED] cc [EMAIL PROTECTED] Subject Re: [PHP-DB] csv export...? It looks like is not so simple. But is not difficult at all.. Try to make something like: ?php header(Content-type: text/csv); $query = SELECT * FROM tables; $result = mysql_query($query); while($row = mysql_fetch_row($result)){ print implode(,, $row); } mysql_free_result($result); ? Check if functions like implode has the correct arguments. Anyway hopes it gives you a clue about what is going on. Don't forget to connect to database first of all. - Original Message - From: [EMAIL PROTECTED] To: Viorel Dragomir [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, January 09, 2004 17:52 Subject: Re: [PHP-DB] csv export...? Cheers for prompt reply... But.. what? I need to take an SQL query, and export teh results to a csv file... Are you really sure that simply pointing to a non existant csv file does that? I don't see it somehow...? I'm sorry if I'm wrong... Viorel Dragomir [EMAIL PROTECTED] 09/01/2004 15:50 To [EMAIL PROTECTED], [EMAIL PROTECTED] cc Subject Re: [PHP-DB] csv export...? You didn't try to hard isn't it! :) If you want to save a file as csv just save the vars like this 1,2,3 4,5,6 ... 0,0,0 If you want to link a csv file for download put a href='file.csv'download/a. It's not so hard after all. :) Or I didn't get your message. Anyway, good luck! - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, January 09, 2004 17:35 Subject: [PHP-DB] csv export...? Google is not my friend today... I have a reportng tool on a database i have, and I want to be able to exort the selected results (I've saved the SQL query as a session variable for ease of use) and save that data as a csv file... with headers if possible... Now I have found loadsa sites that let me upload a csv file, but not the other way around... Anyone care to help? * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. ***
Re: [PHP-DB] csv export...?
Tristan -- ...and then [EMAIL PROTECTED] said... % % Getting there... % That did indeed output my results to the screen... Yay! % Next steo is to output that same data to a new file... A file on the surfer's computer or a file on your server? % % I've done downloads on my site elsewhere, using header(), but with % existing files... % I guess I need to learn how to use fwrite? Only if you plan to store the result file on your server, and since you have the DB there I don't see why you would. HTH HAND HNY :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP-DB] csv export...?
On the users computer... When my bosses look at the reporting tool I built. They are gonna hit the export link, and get directed to a page that let's them save the data as a csv file, for use in excel. That's the code I'm working on here today... ho hum... is it the weekend yet ;-) David T-G [EMAIL PROTECTED] 09/01/2004 16:33 To PHP DB list [EMAIL PROTECTED] cc [EMAIL PROTECTED] Subject Re: [PHP-DB] csv export...? Tristan -- ...and then [EMAIL PROTECTED] said... % % Getting there... % That did indeed output my results to the screen... Yay! % Next steo is to output that same data to a new file... A file on the surfer's computer or a file on your server? % % I've done downloads on my site elsewhere, using header(), but with % existing files... % I guess I need to learn how to use fwrite? Only if you plan to store the result file on your server, and since you have the DB there I don't see why you would. HTH HAND HNY :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] csv export...?
Tristan -- ...and then [EMAIL PROTECTED] said... % % On the users computer... OK; that's what I figured. % When my bosses look at the reporting tool I built. % They are gonna hit the export link, and get directed to a page that let's % them save the data as a csv file, for use in excel. Yep. % That's the code I'm working on here today... Look at the header() lines in my reply outside of this subthread. % % ho hum... is it the weekend yet ;-) Not quite, but you're closer :-) HTH HAND HNY :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP-DB] csv export...?
Google works!!! just found this, and it works: On the other side it may be better and easier to create a csv file on the fly. Create a page, say csv-export.php, and link to it using a href="" This way the user's browser is tricked that the link points to a CSV file, if it does not honor the content-type it sends (see below). David T-G [EMAIL PROTECTED] 09/01/2004 16:42 To PHP DB list [EMAIL PROTECTED] cc [EMAIL PROTECTED] Subject Re: [PHP-DB] csv export...? Tristan -- ...and then [EMAIL PROTECTED] said... % % On the users computer... OK; that's what I figured. % When my bosses look at the reporting tool I built. % They are gonna hit the export link, and get directed to a page that let's % them save the data as a csv file, for use in excel. Yep. % That's the code I'm working on here today... Look at the header() lines in my reply outside of this subthread. % % ho hum... is it the weekend yet ;-) Not quite, but you're closer :-) HTH HAND HNY :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php