Jump to content

Saving displayed table as CSV file.


nottaclu

Recommended Posts

I have a dynamic php page that has a series of select boxes at the top.  When the user changes what is in the select boxes a div at the bottom of the page gets populated with a table via an ajax call to a php script.  I am need of a button on that page that a user can click that will give them the option to save that displayed table as a .csv file.  I have been looking all over for a solution that will work in both ie and ff, and am not coming up with anything.  Any help would be great.  Thanks!

Link to comment
Share on other sites

javascript cannot save files. You can use javascript to grab the table data off the page and send it back to your server. You can do it via AJAX method if you want. Then you'd use php to just generate a file, you can use fputcsv (follow the example in the doc). If you do not want to save it to a file on your server, modify with this comment)

Link to comment
Share on other sites

If you want to save the file on your server, then if you want, you can return a link to the file to click. If you do not care about saving it to the server as a file, just the instructions in the comment link and it will return it back directly as a file to be output. It will open a dialog to the user to save or view it, same as directly clicking on any other yoursite.com/someFile.csv link

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.