exporting a mysql table to excel format via a php program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sharmilah
    New Member
    • Jun 2007
    • 20

    #1

    exporting a mysql table to excel format via a php program

    Hi all

    I have a php program accessing a mysql database. I want users to be able to run reports via the program. But I also want to export the results of my query to excel by clicking on a push button present on my screen. Is there any function which can do the export to excel format. I would be grateful if anyone could provide me this info.

    Thanks
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    There probably is a class kicking around that will achieve this, but it is very easy to write to a CSV file using the fopen(), fwrite() php functions.
    Place the data within a string with the data fields seperated by commas and each record terminated with carriage return newline.
    ie
    [PHP]$handle = fopen('filename ','w');
    fwrite($handle, "data1,data2,da ta3,data3 \r\n");
    fclose();[/PHP]

    Comment

    Working...