Export Table to .csv (tab delimited)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FallingReign
    New Member
    • Mar 2007
    • 8

    Export Table to .csv (tab delimited)

    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,affiliate s WHERE sales.refid=aff iliates.refid group by email")
    or die ("Database Error");

    if (mysql_num_rows ($result))
    {

    print "<font face=arial><TAB LE border=1 cellspacing=0 cellpadding=3 align=center>";
    print "<TR><TH>Pa yPal Account</TH><TH>Payment</TH><TH>Type</TH>";
    print "<TH>Referr er</TH>";
    print "<TH>Messag e</TH></TR>";

    while($info = mysql_fetch_arr ay( $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
  • FallingReign
    New Member
    • Mar 2007
    • 8

    #2
    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...

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

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

      Ronald :cool:

      Comment

      • FallingReign
        New Member
        • Mar 2007
        • 8

        #4
        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...

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

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

          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:

          Comment

          Working...