Jump to content

Issue Writing Code for Download CSV File


KateMacwil

Recommended Posts

Hi

I have written php code that displays to the user a list of all tenders in a database table.
The user can sort on options displayed in the dropdown box and once a filter option
is selected, the view automatically updates based on the selection.

This part is working for me.

However, I was trying to write code so that when you click the Download image on
the page, a csv file is created containing the contents of the filtered view that is
currently displayed.

This part isn't working for me and any help pointing me in the right direction would
be much appreciated.

 

tender-functions.php

tenders-list.php

Link to comment
Share on other sites

It looks like you're trying to use Javascript to run a PHP function, that's not how it works.  Javascript and PHP are not connected like that.  If you check your browser's error console, you'll probably see an error message that says something like CreateDownloadFile is undefined or not a function, that's because it's not a Javascript function.

One option is to create a hidden iframe on the page, and use Javascript to set the src of that iframe to a PHP file that will generate the file, and you pass whatever data you need so that PHP creates the correct file.  You can pass that data in the URL when you set the src of the iframe.  If PHP responds with the correct download headers, then the user will just see a file open/save dialog box pop up that will let them open or save the file.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...