Bonjour à tous,
Je suis actuellement en stage et je bute actuellement une fonction d'export en csv qui ne se déclenche pas. J'ai essayé de retourner le problème dans tous les sens, quand j'arrive à cette fonction, il ne se passe rien.
Voici le code:
La fonction d'export:
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 function action() { $return = ""; if(isset($_GET['sType'])) { if($_GET['sType']=='exporter') { $this->query_to_csv("SELECT * FROM winedb__siteTastedJournal__degustationInscription", "test.csv", true); header("location: http://www.winedb.fr/admin.php?page=siteTastedJournal&type=degustation&sType=inscriptions"); } if($_GET['sType']=="getSelect" && isset($_POST['theSelect']) && isset($_POST['theSelectId'])) { $this->actionGetSelect($_POST['theSelect'],$_POST['theSelectId']); } if($_GET['sType']=="addEtatBouteille" && isset($_POST['produit']) && isset($_POST['bt']) && isset($_POST['val'])) { $return = $this->actionAddEtatBouteille(); } if($_GET['sType']=="ajouterInscription") { $this->actionAjouterInscription(); header("location: http://www.winedb.fr/admin.php?page=siteTastedJournal&type=degustation&sType=inscriptions&id=".$_POST['form_id_degustation']); } if($_GET['sType']=="modifierInscription" && isset($_POST['form_id']) && is_numeric($_POST['form_id']) && $_POST['form_id']!=0) { $this->actionModifierInscription(); } if($_GET['sType']=="ajouter") { $this->actionAjouter(); header("location: http://www.winedb.fr/admin.php?page=siteTastedJournal&type=degustation"); } if($_GET['sType']=="modifier" && isset($_GET['id']) && is_numeric($_GET['id'])) { $this->actionModifier(); header("location: http://www.winedb.fr/admin.php?page=siteTastedJournal&type=degustation"); } if($_GET['sType']=="inscription" && isset($_GET['todo']) && isset($_GET['id']) && is_numeric($_GET['id'])) { $this->actionSetArchiveInscription($_GET['todo'],$_GET['id']); } } // print_r($_POST); return $return; }
Tous les chemins se font bien mais quand je clique sur exporter, voici ce qu'il me sort :
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
28 function query_to_csv($query, $filename, $attachment = false, $headers = true) { if($attachment) { // send response headers to the browser header( 'Content-Type: text/csv' ); header( 'Content-Disposition: attachment;filename='.$filename); $fp = fopen('php://output', 'w'); } else { $fp = fopen($filename, 'w'); } $result = mysql_query($query, $db_conn) or die( mysql_error( $db_conn ) ); if($headers) { // output header row (if at least one row exists) $row = mysql_fetch_assoc($result); if($row) { fputcsv($fp, array_keys($row)); // reset pointer back to beginning mysql_data_seek($result, 0); } } while($row = mysql_fetch_assoc($result)) { fputcsv($fp, $row); } fclose($fp); }
[IMG][/IMG]
En vous remerciant par avance![]()
Partager