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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
<?php
header('Content-Type: application/octet-stream; charset=iso-8859-1');
header("Content-disposition: filename=export.csv");
include('../pages/connect.php');
$hostname = $hote; // nom du serveur
$database = $base; // nom de la base de données
$username = $user; // nom de l'utilisateur
$password = $mdp; // mot de passe
$db = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
// Sélection de la base
mysql_select_db($database,$db);
$req = str_replace("\'","'",$_REQUEST['req']);
$fichier = "../exports/export.csv";
$myfile = fopen($fichier,"w");
$resQuery = mysql_query($req) or die (mysql_error());
$num = mysql_num_rows($resQuery);
if ($num > 0) {
echo mysql_field_name($resQuery, 1).";";
echo mysql_field_name($resQuery, 17).";";
echo mysql_field_name($resQuery, 16).";";
echo mysql_field_name($resQuery, 4).";";
echo mysql_field_name($resQuery, 2).";";
echo mysql_field_name($resQuery, 3).";";
echo mysql_field_name($resQuery, 9).";";
echo "\n";
echo "\n";
/*$champs = ("$num_m, $marque, $type, $nom_util, $service, $unite, $adrip");
// données de la table
while ($champs = mysql_fetch_array($resQuery, MYSQL_ASSOC)) {
foreach($champs as $elem) {
echo "$elem;";
}
echo "\n";
}*/
$champs = ("$num_uc, $marque, $type, $nom_util, $service, $unite, $adrip");
while ($donnees = mysql_fetch_array($resQuery, MYSQL_ASSOC)) {
//Selection des informations pour l'adresse IP
foreach($champs as $elem) {
echo $donnees[$elem];
}
echo "\n";
}
}else{
echo 'Aucune fiche trouvée';
echo '<a href="../body.php">Retour</a>';
exit;
}
mysql_close();
fclose($myfile);
?> |
Partager