Ahoj všem, prosím si o radu s pomocí ukládání řádků databáze do souboru CSV.
V ve sloupečku message mám několikařádkovou zprávu např:
Ahoj,
jak se máš.
Ale můj kód ořízne to "jak se máš." Tedy do CSV mi zapíše pro ten sloupeček "message" pouze první řádek zprávy, čili pouze "Ahoj," zbytek ořízne.
Ahoj,
Takhle vypadá klíčová část mého kódu:
$formular = $_GET["formular"];
$terminOd = $_GET["od"];
$terminDo = $_GET["do"];
$sql = "SET NAMES utf8;";
$sql = "
SELECT $dbtableForms.id,$dbtableRegistration.id AS id,$dbtableRegistration.id_form,$dbtableRegistration.date,$dbtableRegistration.name,$dbtableRegistration.email,$dbtableRegistration.message
FROM $dbtableRegistration LEFT JOIN `$dbtableForms` ON $dbtableRegistration.id_form=$dbtableForms.id
WHERE ($dbtableRegistration.id_form = $formular) AND ($dbtableRegistration.date BETWEEN '$terminOd' AND '$terminDo');
";
//echo $sql;
$result=mysqli_query($conn, $sql);
function mysqli_field_name($result, $field_offset)
{
$properties = mysqli_fetch_field_direct($result, $field_offset);
return is_object($properties) ? $properties->name : null;
}
function convertToWindowsCharset($string) {
$encoding = mb_detect_encoding($string);
return iconv($encoding, "Windows-1252", $string);
}
if (!$result) die('Couldn\'t fetch records');
$num_fields = mysqli_num_fields($result);
$headers = array();
for ($i = 0; $i < $num_fields; $i++) {
$headers[] = mysqli_field_name($result , $i);
}
$fp = fopen('php://output', 'w');
if ($fp && $result) {
// //header('Content-Encoding: UTF-8');
// //header('Content-Encoding: Windows-1252');
// header('Content-Type: text/csv');
// //header('Content-Type: text/csv; charset=utf-8');
// //header('Content-Type: text/csv; charset=Windows-1252');
// header('Content-Disposition: attachment; filename="export.csv"');
// header('Pragma: no-cache');
// header('Expires: 0');
header('Content-Description: File Transfer');
header('Content-Type: text/csv; charset=UTF-16LE');
header('Content-Disposition: attachment; filename=export.csv');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
fputs( $fp, "\xEF\xBB\xBF" );
fputcsv($fp,$headers,";",'"');
while ($row = $result->fetch_array(MYSQLI_NUM)) {
fputcsv($fp,array_values($row),";",'"');
}
die;
}
$conn->close();
Děkuji všem moc za rady.