SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast kewlistantikewl's Avatar
    Join Date
    Sep 2003
    Location
    Canada
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Adding column headings to a csv download

    Hi there,

    I am downloading a csv file for specific queries on my db and i know you can attach the column headings if i were to export it using phpmyadmin but i would like to be be able to do it so my users can just click on a link.

    here is what i have to create and download the file any help would be grealy appreciated.

    Code:
    /*Generate .csv File for download*/
    		$result=mysql_query($sql); 
    		header ('Content-type: application/excel'); 
    		header ('Content-Description: PHP Generated Data'); 
    		header ('Content-Disposition: inline; filename="SIC_Download.csv"'); 
    		while ($row=mysql_fetch_row($result)){ 
    			echo implode (',',$row)."\n"; 
    		}
    Lost:PHP coding skills if found please call 1-800-Need-PHP

  2. #2
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you just add the following before your While statement?

    Code:
      //echo column headings
    
     echo ("Col1,Col2,Col3,etc,etc\n"); 
    
    //your code
    while ($row=mysql_fetch_row($result)){ 
    			echo implode (',',$row)."\n"; 
    		}

  3. #3
    SitePoint Enthusiast kewlistantikewl's Avatar
    Join Date
    Sep 2003
    Location
    Canada
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you that worked!
    Lost:PHP coding skills if found please call 1-800-Need-PHP


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •