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
https://forums.phpfreaks.com/topic/259847-export-sql-query-to-pdf-or-csv-with-php/
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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.