Удалить первую строку файла - PullRequest
0 голосов
/ 17 января 2019

У меня проблема с экспортом моего CSV. Да, он может экспортировать, но при экспорте имя colmun включено. Как удалить первую строку (имя столбца) после экспорта?

Пробовал искать другое решение, но оно не подходит для моей программы

<?php
//include database configuration file
include 'config2.php';

//get records from database
$query = $db->query("SELECT * FROM maternalproblem ");

if($query->num_rows > 0){
    $delimiter = ",";
    $filename = "maternalproblem" . date('Y-m-d') . ".csv";

    //create a file pointer
    $f = fopen('php://memory', 'w');

    //set column headers
    $fields = array('MPID', 'district_id', 'barangay_id', 'PID', 'tuberculosis', 'sakit','diyabetes','hika','bisyo');
    fputcsv($f, $fields, $delimiter);

    //output each row of the data, format =line as csv and write to file pointer
    while($row = $query->fetch_assoc()){

        $lineData = array($row['MPID'], $row['district_id'], $row['barangay_id'], $row['PID'], $row['tuberculosis'],$row['sakit'],$row['diyabetes'],$row['hika'],$row['bisyo']);
        df.to_csv($filename , header=False);
        fputcsv($f, $lineData, $delimiter);
    }

    //move back to beginning of file
    fseek($f, 0);

    //set headers to download file rather than displayed
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment; filename="' . $filename . '";');

    //output all remaining data on a file pointer
    fpassthru($f);
}
exit;

?>

Мне просто нужно экспортировать данные, а не с именем столбца. Спасибо

1 Ответ

0 голосов
/ 17 января 2019

Вероятно, было бы проще просто не помещать заголовки столбцов в файл

Так удалите эти строки

//set column headers
$fields = array('MPID', 'district_id', 'barangay_id', 'PID', 'tuberculosis', 'sakit','diyabetes','hika','bisyo');
fputcsv($f, $fields, $delimiter);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...