Reputation: 109
Is possible in a webpage create a button that export a specific table with PHP?
Example: I click the button "Export Contacts" and this call a function that return me a .csv file of the table "contacts", for example.
Upvotes: 2
Views: 129
Reputation: 11310
Here is the simple way to export the data to csv file. You can use this.
<?php
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$fp = fopen('file.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
Here is the link http://www.php.net/manual/fr/function.fputcsv.php
Upvotes: 1