$req1="select * from table1";
$res1=mysql_query($req1);
while ($t1=mysql_fetch_row($res1)){
//affichage éléments
echo $t1[1]
$req2="select * from table2 where id='$t1[0]'";
$res2=mysql_query($res2);
//si résultats affichage
while ($t2=mysql_fetch_row($res2)){
echo $t2[1];
}
}
Normalement ca passe
Code : Tout sélectionner
SELECT tab2.valeur
FROM table2 AS tab2
LEFT JOIN table1 AS tab1
ON tab2.index = tab1.index
WHERE tab1.index IS NULL
Code : Tout sélectionner
SELECT elements.Details as toto, defaut.Description as tata ,count(*) as titi
FROM expertise, elements, defaut
WHERE expertise.Element=elements.ID and expertise.Defaut=defaut.ID and expertise.Defaut>1 and defaut.id=2
GROUP BY expertise.Element, expertise.Defaut
ORDER BY toto DESC Code : Tout sélectionner
SELECT elements.Details as toto, defaut.Description as tata ,count(*) as titi
FROM expertise
LEFT OUTER JOIN elements ON expertise.Element = elements.ID
LEFT OUTER JOIN defaut ON expertise.Defaut = defaut.ID
WHERE expertise.Defaut > 1
AND defaut.id = 2
GROUP BY expertise.Element, expertise.Defaut
ORDER BY toto DESCCode : Tout sélectionner
table_1
+--------+-------------+
| tb1_id | tb1_element |
+--------+-------------+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
+--------+-------------+
table_2
+--------+--------+-------------+
| tb2_id | tb1_id | tb2_valeurs |
+--------+--------+-------------+
| 1 | 1 | 2 |
| 2 | 3 | 7 |
| 3 | 3 | 5 |
| 4 | 4 | 7 |
| 5 | 1 | 6 |
| 6 | 1 | 4 |
| 7 | 4 | 7 |
+--------+--------+-------------+Code : Tout sélectionner
mysql> SELECT t1.tb1_element AS 'Eléments', COUNT(tb2_valeurs) AS 'nombre de valeurs'
-> FROM table_1 AS t1 LEFT JOIN table_2 AS t2
-> ON t2.tb1_id = t1.tb1_id
-> GROUP BY t1.tb1_element;
+----------+-------------------+
| Eléments | nombre de valeurs |
+----------+-------------------+
| a | 3 |
| b | 0 |
| c | 2 |
| d | 2 |
+----------+-------------------+
Code : Tout sélectionner
T1 T2 T3
-----------------------------
A -------> B ---------> C
B ---------> D
A -------> E