Code : Tout sélectionner
SELECT
A.Code_A as 'CodeTableA',
B.Nom_ChampB as 'LibelleTableB',
FROM TableA A
LEFT JOIN TableC C ON (A.Code_A = C.Code_C)
LEFT JOIN TableB B ON (C.Code_C = B.Code_B)
WHERE A.Code_A = #valeur#
$idA ="";
while ($resultat = mysql_fetch_array($req)){
// si c'est un nouveau codeA, on passe à la ligne et on l'affiche
if ($id != $resultat['CodeTableA']) {
print "<br>".$resultat['CodeTableA']." : ";
$id =$resultat['id'];
}
print " ".$resultat['CodeTableB'];
}
J'ai pas eu le temps de tester, mais l'idée doit y être Code : Tout sélectionner
Select C.CA,
Case count(*)
when 1 then ( Select C2.CB From C2 Where C2.CA=C.CA LIMIT 0 TO 1 )
when 2 then ( Select C2.CB From C2 Where C2.CA=C.CA LIMIT 0 TO 1 )
+( Select C2.CB From C2 Where C2.CA=C.CA LIMIT 1 TO 2 )
when 3 then ( Select C2.CB From C2 Where C2.CA=C.CA LIMIT 0 TO 1 )
+( Select C2.CB From C2 Where C2.CA=C.CA LIMIT 1 TO 2 )
+( Select C2.CB From C2 Where C2.CA=C.CA LIMIT 2 TO 3 )
else 'etc ....'
end
From C
Group By C.CAfunction export_XLS($req, $Fnm, $db) {
//include("fct_nettoiexls.php");
nettoie_XLS();
// Calcul la date et l'heure de génération du fichier EXCEL
$date = date("Ymd-His");
// Composition du nom unique du fichier EXCEL
$Fnm = "export/".$date."_".$Fnm;
//$Fnm = "export/".$Fnm;
if (file_exists($Fnm)) {
unlink($Fnm);
}
// Ouverture du fichier en ecriture
$inF = fopen($Fnm,"w+");
fputs($inF,"<table border='1'>\n");
if ($req) {
$res = mysql_db_query($db,$req) or die ("MESSAGE d'ERREUR : ".mysql_error(). " - ".$req);
$i = 0;
//Construction de l'entete du tableau
$chaine = "<tr bgcolor='#EECC11'>";
while ($i < mysql_num_fields($res)) {
$meta = mysql_fetch_field($res, $i);
if (!$meta) {
echo "Aucun champ n'est disponible<br>\n";
}
$chaine .= "<th>".$meta->name."</th>";
$i++;
}
$chaine .= "</tr>";
fputs($inF,$chaine);
while ($row = mysql_fetch_array($res)) {
$chaine = "<tr>";
for ($i=0 ; $i < mysql_num_fields($res) ; $i++) {
$chaine .= "<td>".$row[$i]."</td>";
}
$chaine .= "</tr>\n";
fputs($inF,$chaine);
}
}
else {
echo "Aucune requête n'a été spécifiée...";
}
fputs($inF,"</table>");
fclose($inF);
return $Fnm;
}
Aux vus de ce code, tu comprends bien, qu'il est difficile (voire impossible d'adopter ta solution (qui est très bonne cependant)).