Issue
I am trying to export data from MySQL to xlsx but in my database may have some 0 and 1 instead of real data. Let me explain better: There's a column used to set if it's day or night but using 0 to day and 1 to night. When i export using the code bellow, i get a xlsx with these 0 and 1.
Already tried stuff like https://phppot.com/php/database-data-export-to-excel-file-using-php/ and https://artisansweb.net/how-to-export-mysql-database-data-to-excel-using-php/ but i just can't edit what's going to xlsx before sending
$filename = "Export_excel.xls";
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"$filename\"");
$isPrintHeader = false;
if (! empty($productResult)) {
foreach ($productResult as $row) {
if (! $isPrintHeader) {
echo implode("\t", array_keys($row)) . "\n";
$isPrintHeader = true;
}
echo implode("\t", array_values($row)) . "\n";
}
}
When the code see a zero, i want to set it to "day"
Solution
If you want to show specific fields only.
select id,name, ( CASE WHEN table_column = 0 THEN 'day' WHEN table_column = 1 THEN 'night' END ) as table_column from your_table
Output Look Like:
id name table_column
1 Lucas day
Answered By - Siddhart hundare Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.