Web Analytics Made Easy -
StatCounter Save mysql text data to file? - CodingForum


No announcement yet.

Save mysql text data to file?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Save mysql text data to file?

    I'm trying to create a button that exports two columns of text from a mysql table to an ASCII file (or something users can load into Excel). Can anyone give me any direction? Thanks.

  • #2
    Couple of questions:

    Will your users be accessing this over the web? Will they have access to the server?

    PHP can be used to query the database and display the results (2 columns in your case) in text format.

    However, this page will be a .php page still.

    You have a couple of options:

    You can have this button create this text format and have your users save the file as something.txt somewhere on their hard drive. They can then import the file into excel or whatever.

    That's the easy way.

    Another option would be to do the same but then use javascript to attempt to bring up the saveAs dialog box, allowing the user to save the file. I'm not sure, but I think you can set the type of the save file to txt... you'd have to look into that.

    That's not too much more work. But either way, at least in my opinion, you'd have to first display the data from the database as you normally would, and format it using print statements -- not using any html for formatting.

    Hope that helps,


    • #3
      actually, I was just re-reading my post and I don't think the second option is actually an option as you will need to insert HTML and javascript to make it work.

      When they save the file, it won't be pure text anymore, but it'll have your javascript functions and stuff too.

      I would say to just output all the data and ensure you don't include any html.

      you may even be able to get your server to treat .txt files as php extensions, and have your php code to generate the text file that way.

      That's all I can think of. It's Friday!! Yay!!



      • #4
        CodingForum Supreme Overlord
        All Hail Spookster


        • #5
          To both of you:
          Thanks a lot! I think I'm on my way.