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";
}