Bonjour a tous,

Je me retrouve un peut coincer a l'heure actuelle.
Je souhaiterais pouvoir exporter des données de ma BD vers un fichier CSV.
Pour cela j'ai commencer à suivre un tuto plutot bien expliquer, j'arrive a créer le fichier csv, mais je doit avoir un problème dans ma requête.
Impossible d'obtenir plus d'une valeur !

Voici le code actuel:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
header('Content-Type: text/csv;');
header('Content-Disposition: attachment; filename="test.csv"');
 
// This is an example of config.php
$dbhost = '****';
$dbuser = '****';
$dbpass = '****';
$dbname = '****';
 
// This is an example opendb.php
 
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
 
$req=mysql_query("SELECT id_formation, titre_formation, cout FROM form_formations");
 
$data=mysql_fetch_array($req);
 
print_r($data);
?>"Id";"Titre";"Cout"<?php
 
foreach($data as $d){
 
echo "\n".'"'.$d->id_formation.'";"'.$d->titre_formation.'";"'.$d->cout.'"';
}
?>
Merci d'avance.