-1

I am trying to export tables into excel. the tables in my query are selected using submit, for example :- Date1 and Date2 and type (From dropdown) is selected, then on submit, the table based on type will appear, and i want to export it to excel.

Aamir
  • 1,713
  • 1
  • 22
  • 49
  • What did you already try? Did you already Google this problem? If you're unsure on how to proceed, split up your problem in multiple steps and think about solving each step. Possible solutions: export your data as Comma Separate Values (CSV) file, which can easily be loaded in Excel. – xaviert Feb 22 '16 at 07:10

1 Answers1

1

If you absolutely need to export the data to a native Excel file have a look at PHPExcel. It's an excellent library for manipulating Excel files but it would be complicated for a newcomer to PHP. Otherwise, if you're happy exporting as a CSV and converting to an Excel file later look at the native fputcsv() function.

Also check this question here

You can try this to simple put php variable to excel using fputcsv().

define('CSV_PATH','csvfiles/'); // specify CSV file path

$csv_fileoutput = CSV_PATH . "output.csv"; // Name of your CSV file 
$csvfileoutput = fopen($csv_fileoutput, 'a');

fputcsv($csvfileoutput, array($productnumber,$id,$name,$address,$phone_no));
// php variable which stores value of mysql query. 
Community
  • 1
  • 1
CodeGuy
  • 753
  • 1
  • 8
  • 40
  • i am new to PHP..I dont know how to implement PHP Excel. – Priya Bajaj Feb 22 '16 at 06:43
  • these attributes as u mentioned above are not fixed, my table will change according to type selected. – Priya Bajaj Feb 22 '16 at 06:51
  • so you can store mysql row value in php variable like if you use mysql_fetch_array() then row[0] value can be store in $phpvar1 and so on then store this variable using fputcsv. – CodeGuy Feb 22 '16 at 07:28
  • Sorry I didnt get that – CodeGuy Feb 22 '16 at 07:39
  • my Query is divided into 4 steps.... Search , fetch , display and export. search will fetch different tables based on type selected , upto display its working properly. now i want to export the selected table.how can i do ?? – Priya Bajaj Feb 24 '16 at 05:13
  • are you storing data in html tables ?? show me how your data is displayed. Also I am not able to post answer here .. – CodeGuy Feb 24 '16 at 05:45
  • yes m storing in html tables.. – Priya Bajaj Feb 24 '16 at 06:51
  • if(isset ($_POST['export'])){ if (is_array($result)){ $fp = fopen('file2.csv', 'w'); foreach ($result as $row) { fputcsv($fp, $row); } fclose($fp); echo $result; } } – Priya Bajaj Feb 24 '16 at 06:52
  • i did this coding on export button...but nothing is being viewed...no page no table – Priya Bajaj Feb 24 '16 at 06:52
  • Have a look at this http://stackoverflow.com/questions/16078544/export-to-csv-using-jquery-and-html/16203218 and here https://editor.datatables.net/examples/extensions/exportButtons.html – CodeGuy Feb 24 '16 at 07:03
  • in these links....work is being done only on one table...and second link works correctly but my query is based on submit selection..m stuck..someone suggested me to apply the code for foreach array..but no working – Priya Bajaj Feb 24 '16 at 08:08
  • Show me your code. I can not figure out like this.. – CodeGuy Feb 24 '16 at 08:16