diff --git a/ecrire/public/boucles.php b/ecrire/public/boucles.php
index 68a4e711f75be0cc9403d18c2bd05999ed19e48c..d03e017c8019428c5181d2f709c1fe75c407eca3 100644
--- a/ecrire/public/boucles.php
+++ b/ecrire/public/boucles.php
@@ -290,10 +290,8 @@ function boucle_SYNDIC_ARTICLES_dist($id_boucle, &$boucles) {
 	else {
 		$jointure = array_search("spip_syndic", $boucle->from);
 		if (!$jointure) {
-			$jointure = 'J' . count($boucle->from);
-			$boucle->from[$jointure] = 'spip_syndic';
-			$boucle->where[]= array("'='", "'$id_table" .".id_syndic'",
-						"\"$jointure" . '.id_syndic"');
+			fabrique_jointures($boucle, array(array($id_table, array('spip_syndic'), 'id_syndic')), true, $boucle->show, $id_table);
+			$jointure = array_search('spip_syndic', $boucle->from);
 		}
 		$boucle->where[]= array("'='", "'$mstatut'", "'\\'publie\\''");
 		$boucle->where[]= array("'='", "'$jointure" . ".statut'", "'\\'publie\\''");
diff --git a/ecrire/public/references.php b/ecrire/public/references.php
index c053cff202bce4b8908dfd5447c0381c5352a0b2..ab90a713df51c973f1f90facbb49884f2350180c 100644
--- a/ecrire/public/references.php
+++ b/ecrire/public/references.php
@@ -43,8 +43,9 @@ function index_pile($idb, $nom_champ, &$boucles, $explicite='') {
 	while (isset($boucles[$idb])) {
 		list ($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles);
 		if ($t) {
-		  if (!in_array($t, $boucles[$idb]->select))
+		  if (!in_array($t, $boucles[$idb]->select)) {
 		    $boucles[$idb]->select[] = $t;
+		  }
 		  return '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']';
 		}
 #		spip_log("On remonte vers $i");
@@ -117,17 +118,15 @@ function index_exception(&$boucle, $desc, $nom_champ, $excep)
 		if ($t == NULL) {
 			list($e, $x) = $excep;	#PHP4 affecte de gauche a droite
 			$excep = $x;		#PHP5 de droite a gauche !
+			$j = $trouver_table($e, $boucle->sql_serveur);
+			if (!$j) return array('','');
+			$e = $j['table'];
 			if (!$t = array_search($e, $boucle->from)) {
-				$j = $trouver_table($e, $boucle->sql_serveur);
-				if ($j) {
-					$t = 'J' . count($boucle->from);
-					$boucle->from[$t] = $j['table'];
-					$j = $j['key']['PRIMARY KEY'];
-					$boucle->where[]= array("'='", "'$boucle->id_table." . "$j'", "'$t.$j'");
-				}
+				fabrique_jointures($boucle, array(array($boucle->id_table, array($j['table']), $j['key']['PRIMARY KEY'])));
+				$t = array_search($e, $boucle->from);
 			}
 		}
-	} 
+	}
 	else $t = $boucle->id_table;
 	// demander a SQL de gerer le synonyme
 	// ca permet que excep soit dynamique (Cedric, 2/3/06)