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
|
<?php
// à elle seule, la ligne suivante suffit à envoyer le résultat du script dans une feuille Excel
header("Content-type: application/vnd.ms-excel");
// la ligne suivante est facultative, elle sert à donner un nom au fichier Excel
header("Content-Disposition: attachment; filename=Adherents_SMBC.xls");
//require_once("file:///I|/script php/gestion adherent/conf_int.php");
// La suite est une simple requête php-mysql. On interroge la table utilisée dans l'exemple précédent.
mysql_connect("");
mysql_select_db("");
$requete=mysql_query("SELECT
adherents.nom,
adherents.prenom,
adherents.adresse1,
adherents.adresse3,
adherents.codepostal,
adherents.date_naissance,
adherents.email,
adherents.certificat_medical,
famille.famille,
source.source,
compte.credit
FROM adherents, famille, source, compte
WHERE adherents.famille = famille.id AND adherents.source=source.id AND adherents.id=compte.adherent ORDER BY nom");
</script>";
print '<table border=1>
<TR><TD><strong><center>Nom</center></strong></TD><TD><strong><center>Prénom</center></strong></TD><TD><strong><center>Adresse</center></strong></TD><TD><strong><center>Ville</center></strong></TD><TD><strong><center>CP</center></strong></TD><TD><strong><center>DDN</center></strong></TD><TD><strong><center>E-mail</center></strong></TD><TD><strong><center>CM</center></strong></TD><TD><strong><center>Disciplines</center></strong></TD><TD><strong><center>T</center></strong></TD><TD><strong><center>Réglé</center></strong></TD></TR><TR>';
// lecture du contenu de la requête avec 2 boucles imbriquées; par ligne et par colonne
for ($ligne=0 ; $ligne<mysql_num_rows($requete);$ligne++)
{
for ($colonne = 0;$colonne < 11 ; $colonne++)
{
print '<TD>' .mysql_result($requete,$ligne,$colonne). '</TD>';
}
print '</TR>';
}
// echo mysql_error();
print '</TABLE>';
mysql_close();
?> |
Partager