$requete = "SELECT DISTINCT label FROM motscles ORDER by label";
$res = pg_query($requete);
$i=0 ;
while($data = pg_fetch_array($res)) { //pour chaque enregistrement
$label = str_replace("'","''",$data['label']);
$requete2 = "SELECT iddocument FROM documents WHERE motscles like '%".$label."%' ORDER BY iddocument";
$res2 = pg_query($requete2);
echo $i.' - .|'.$data['label'].'|. -> fiches ';
while($data2 = pg_fetch_array($res2)) {
echo $data2['iddocument'].', ';}
echo '
';
$i = $i +1 ;
}
?>