Connecting Tech Pros Worldwide Forums | Help | Site Map

Export Table to .csv (tab delimited)

Newbie
 
Join Date: Mar 2007
Posts: 8
#1: Mar 9 '07
Hi, i was wondering if anyone could help me export a table that i have created to a tab delimited csv file...

Code example of my Query and print:
[PHP]mysql_connect($server, $db_user, $db_pass)
or die ("Database CONNECT Error");

$result = mysql_db_query($database, "SELECT sum(payment) as payments, email, sales.refid FROM sales,affiliates WHERE sales.refid=affiliates.refid group by email")
or die ("Database Error");

if (mysql_num_rows($result))
{

print "<font face=arial><TABLE border=1 cellspacing=0 cellpadding=3 align=center>";
print "<TR><TH>PayPal Account</TH><TH>Payment</TH><TH>Type</TH>";
print "<TH>Referrer</TH>";
print "<TH>Message</TH></TR>";

while($info = mysql_fetch_array( $result ))
{

print "<TR>";
print "<TD><font size=2>";
print $info['email'];
print "</TD>";

print "<TD><font size=2>";
print $info['payments'];
print "</TD>";
print "<TD><font size=2>";
print "AUD";
print "</TD>";
print "<TD><font size=2>";
print $info['refid'];
print "</TD>";
print "<TD><font size=2>";
print "VicPay Commission Statement";
print "</TD>";
print "</TR>";
}
print "</table>";
} [/PHP]

Now that i have displayed the table correctly in PHP i have no idea how to export it...
is there a way i can have save button or hyperlink to download the file??

thanks
FallingReign

Newbie
 
Join Date: Mar 2007
Posts: 8
#2: Mar 9 '07

re: Export Table to .csv (tab delimited)


Also here is how my tables look in the SQL DB

Database

-Affiliates (table)
--refid
--email
--name
--surename
--etc..

-Sales (table)
--refid
--payment
--type
--etc...
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#3: Mar 9 '07

re: Export Table to .csv (tab delimited)


What version of PHP are you using? If 5.1 or > you can use the fputcsv command. See manual at FPUTCSV

Ronald :cool:
Newbie
 
Join Date: Mar 2007
Posts: 8
#4: Mar 9 '07

re: Export Table to .csv (tab delimited)


Quote:

Originally Posted by ronverdonk

What version of PHP are you using? If 5.1 or > you can use the fputcsv command. See manual at FPUTCSV

Ronald :cool:

Im using Dreamweaver MX 2004 so im not sure what version of PHP that is but that function isn't supported...
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#5: Mar 10 '07

re: Export Table to .csv (tab delimited)


Have a look at the IAM CSV Dump class of phpclasses.org. What it does:

Quote:

Originally Posted by phpclasses

This class takes the results of a SQL query and outputs in the CSV (comma separated values) format.

The class offers the choice of sending the output to the browser or downloading it as a file. The name and extension of the dump file are defined by the developer.

Ronald :cool:
Reply