aithris duilgheadas
Ma tha dàta agad ann an stòr-dàta MySQL. Tha thu a’ cur URL chun neach-cleachdaidh gus an dàta aca fhaighinn a-mach mar fhaidhle CSV.
Ciamar as urrainn dhut, nuair a phutas iad air a’ cheangal, pop-up a bhith agad gus CVS a luchdachadh sìos leis a’ chlàr bho MySQL?
Fuasgladh 1
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
function outputCSV($data) {
$output = fopen("php://output", "wb");
foreach ($data as $row)
fputcsv($output, $row); // here you can change delimiter/enclosure
fclose($output);
}
outputCSV(array(
array("name 1", "age 1", "city 1"),
array("name 2", "age 2", "city 2"),
array("name 3", "age 3", "city 3")
));
Fuasgladh 2
Seo dreach leasaichte den ghnìomh bho php.net. Cuimhnich air exit()
às deidh dhut seo a ghairm ma tha thu deiseil leis an duilleag.
function download_csv_results($results, $name = NULL)
{
if( ! $name)
{
$name = md5(uniqid() . microtime(TRUE) . mt_rand()). '.csv';
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename='. $name);
header('Pragma: no-cache');
header("Expires: 0");
$outstream = fopen("php://output", "wb");
foreach($results as $result)
{
fputcsv($outstream, $result);
}
fclose($outstream);
}
Tha e gu math furasta a chleachdadh agus bidh e ag obair gu math le seataichean toraidh MySQL(i) / PDO.
download_csv_results($results, 'your_name_here.csv');