Jump to content

Export SQL Query to PDF or CSV with PHP


jacko1607

Recommended Posts

I have researched on this and have some solutions – but would like to get some advice on my particular case.

 

The website I am working on is Joomla based. I have a user form which when submitted runs a query on the database and returns values.

 

From this query I require the ability to export the results as either a CSV or PDF (PDF preferred).

 

If possible, I would prefer to avoid any Javascript method to do this as I am not familiar with it.

 

Obviously the simplest and quickest method is preferred but any advice on how to do this?

 

Thanks!

Link to comment
Share on other sites

http://www.fpdf.org/

 

I have used FPDF before and it worked well. I think that, or any other 3rd party resource you can find, is best for PDF creation. No JS required.

 

If you want to create a .csv file that's a simple as:

$csv_array = array(
                                 array('column1', 'column2', 'column3'), //heading row
                                 array('some data here', 'some data there', 'then some more data'), //data row 1
                                 array('some data here', 'some data there', 'then some more data') //data row 2
                                 //etc...
                             );
$handle = fopen('path/to/file/filename.csv', 'w');
foreach($csv_array as $row){
    fputcsv($handle, $row);
}
fclose($handle);

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.