Insert into a CSV file

0

I wanted to insert the table data (SQLite) into a CSV file. I make a query before, and I want to insert the result of that query into the CSV file. There is a fputcsv function in PHP. I can create the file but I wanted to insert it. Here is the code:

for ($i=0; $i<=$nombre;$i++){
        $requete    =   "SELECT * FROM contact WHERE $selectoption='$search' AND id=$i";    
        $resultat   =   $base_hndl->query($requete);    
        $affiche    =   $resultat->fetchArray();//

        echo "<tr>";
            echo "<td>$affiche[nom]</td>";
            echo "<td>$affiche[prenom]</td>";
            echo "<td>$affiche[fonction]</td>";
            echo "<td>$affiche[societe]</td>";
            echo "<td>$affiche[mobile]</td>";
            echo "<td>$affiche[mail]</td>";
        echo "</tr>";

    }

    $fp = fopen($search.".csv", 'w');

        fputcsv($fp, $list);
    fclose($fp);
    echo "ficheiro csv criado";
}
    
asked by anonymous 12.11.2014 / 15:45

1 answer

1

Do not forget to save the data in the $ list?

$list = array();
for ($i=0; $i<=$nombre;$i++){
        ...
        $list[] = $affiche;
        ...
    }

    $fp = fopen($search.".csv", 'w');

        fputcsv($fp, $list);
    fclose($fp);
    echo "ficheiro csv criado";
}
    
12.11.2014 / 16:03