Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<?php session_start(); require_once ("/var/web/dev/mod_oracle/www/_HEAD/oracle.mod.php"); $oConnect = fOraclelogon("...", "...", "..."); //on recupere les infos dans la bdd $sql = "select lc.id# as id_ligne_commande, com.id# as id_commande, com.date_saisie, com.date_prise_en_compte, u.nom||' '||u.prenom as nom_prenom, a.reference as ref_article, a.description as description_article, cat.description as description_categorie, a.prix_unitaire_ht, lc.quantite_article, sum (lc.quantite_article*a.prix_unitaire_ht) as total_article from t_commande com, t_article a, t_ligne_commande lc, t_categorie cat, t_utilisateur u where com.id#=lc.commande_id and u.id#=com.utilisateur_id and a.id#=lc.article_id and cat.id#=a.categorie_id and com.date_prise_en_compte is null group by lc.id#, com.id#, com.date_saisie, com.date_prise_en_compte, u.nom||' '||u.prenom, a.reference, a.description, cat.description, a.prix_unitaire_ht, lc.quantite_article order by com.id#"; $result = fOracleSqlSelect($oConnect , $sql, $aTabSql); if(sizeof($aTabSql)>0) { //Si au moins une ligne est retournée $contenu='COMMANDE N°,DATE DE LA COMMANDE,PERSONNE,REFERENCE,ARTICLE,CATEGORIE,PRIX U HT,QUANTITE,TOTAL'."\r\n"; for($i=0;$i<sizeof($aTabSql);$i++) { if (preg_match("#^,#", $aTabSql[$i]["PRIX_UNITAIRE_HT"])) { $aTabSql[$i]["PRIX_UNITAIRE_HT"] = preg_replace('#,#', '0.',$aTabSql[$i]["PRIX_UNITAIRE_HT"]); } if (preg_match("#,#", $aTabSql[$i]["PRIX_UNITAIRE_HT"])) { $aTabSql[$i]["PRIX_UNITAIRE_HT"] = preg_replace('#,#', '.',$aTabSql[$i]["PRIX_UNITAIRE_HT"]); } if (preg_match("#^,#", $aTabSql[$i]["TOTAL_ARTICLE"])) { $aTabSql[$i]["TOTAL_ARTICLE"] = preg_replace('#,#', '0.',$aTabSql[$i]["TOTAL_ARTICLE"]); } if (preg_match("#,#", $aTabSql[$i]["TOTAL_ARTICLE"])) { $aTabSql[$i]["TOTAL_ARTICLE"] = preg_replace('#,#', '.',$aTabSql[$i]["TOTAL_ARTICLE"]); } } //$contenu = ""; for($i=0;$i<sizeof($aTabSql);$i++) { $contenu = $contenu.$aTabSql[$i]["ID_COMMANDE"] .",".$aTabSql[$i]["DATE_SAISIE"] .",".$aTabSql[$i]["NOM_PRENOM"] .",".$aTabSql[$i]["REF_ARTICLE"] .",".strip_tags(stripslashes($aTabSql[$i]["DESCRIPTION_ARTICLE"])) .",".strip_tags(stripslashes($aTabSql[$i]["DESCRIPTION_CATEGORIE"])) .",".$aTabSql[$i]["PRIX_UNITAIRE_HT"] .",".$aTabSql[$i]["QUANTITE_ARTICLE"] .",".$aTabSql[$i]["TOTAL_ARTICLE"]."\r\n"; } $file="commandes.csv"; $fp=fopen($file,"w" ); // ouverture du fichier fputs($fp,$contenu); // enregistrement des données ds le fichier fclose($fp); header("Content-Type: application/force-download" ); header("Content-Length: ".filesize($file)); header("Content-Disposition: attachment; filename=".$file); readfile($file); unlink($file); } ?>