Bonjour,

Je développe actuellement un site web en php/mysql et j'ai un petit souci de requête, je vous joins le schéma des tables ainsi que les requêtes qui ne fonctionnent pas. Le problème est le suivant: Lorsque les stats de l'équipe domicile sont mises à jour, celles de l'équipe extérieure est effacée et vis versa.

schéma des tables:
tab_stats: numClub, refChamp, nbPts, nbVic, nbNul, nbDef, nbBp, nbBc
tab_match: numClubDom, numClubExt, numJournee, refChamp, scoreDom, scoreExt, penaltiesDom, penaltiesExt, joue

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//MISE A JOUR MATCH
$ins="update tab_match set scoreDom='".$sdom."', scoreExt='".$sext."' 
	where numClubDom=".$ndom." and refChamp=".$refch." and                            numJournee=".$njour;
$res=mysql_query($ins, $connexion) or die("Erreur lors de la mise à jour du match");
 
//MISE A JOUR STATS EQUIPE DOM
$cladom="update tab_stats STA
SET nbPts=
(select case when (MAT.scoreDom > MAT.scoreExt) then (nbPts + 4) 
		 when (MAT.scoreDom = MAT.scoreExt) then (nbPts + 2)
		 else nbPts+1 end from tab_match MAT
where STA.numClub=".$ndom." and STA.refChamp=MAT.refChamp
 and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbVic=
(select case when (MAT.scoreDom > MAT.scoreExt) then (nbVic + 1) 
		 else nbVic end from tab_match MAT
where STA.numClub=".$ndom." and STA.refChamp=MAT.refChamp
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbNul=
(select case when (MAT.scoreDom = MAT.scoreExt) then (nbNul + 1)
                  else nbNul end from tab_match MAT
where STA.numClub=".$ndom." and STA.refChamp=MAT.refChamp
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbDef=
(select case when (MAT.scoreDom < MAT.scoreExt) then (nbDef + 1)
                  else nbDef end from tab_match MAT
where STA.numClub=".$ndom." and STA.refChamp=MAT.refChamp
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbBp=nbBp+(select MAT.scoreDom from tab_match MAT
where STA.numClub=".$ndom." and STA.refChamp=MAT.refChamp
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbBc=nbBc+(select MAT.scoreExt from tab_match MAT
where STA.numClub=".$ndom." and STA.refChamp=MAT.refChamp
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch.")";
 
$rcladom=mysql_query($cladom, $connexion) or die("Erreur de mise à jour pour l'équipe domicile");
 
//MISE A JOUR STATS EQUIPE EXT
$claext="update tab_stats STA
SET nbPts=
(select case when (MAT.scoreDom < MAT.scoreExt) then (nbPts + 4) 
		 when (MAT.scoreDom = MAT.scoreExt) then (nbPts + 2)
		 else nbPts+1 end from tab_match MAT
where STA.numClub=MAT.numClubExt and STA.refChamp=MAT.refChamp and MAT.numClubDom=".$ndom." and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbVic=(select case when (MAT.scoreDom < MAT.scoreExt) then (nbVic + 1) 
			  else nbVic end from tab_match MAT
where STA.numClub=MAT.numClubExt and STA.refChamp=MAT.refChamp and MAT.numClubDom=".$ndom."
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbNul=(select case when (MAT.scoreDom = MAT.scoreExt) then (nbNul + 1)
                          else nbNul end from tab_match MAT
where STA.numClub=MAT.numClubExt and STA.refChamp=MAT.refChamp and MAT.numClubDom=".$ndom."
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbDef=(select case when (MAT.scoreDom > MAT.scoreExt) then (nbDef + 1)
                          else nbDef end from tab_match MAT
where STA.numClub=MAT.numClubExt and STA.refChamp=MAT.refChamp and MAT.numClubDom=".$ndom."
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbBp=nbBp+(select MAT.scoreExt from tab_match MAT
	         where STA.numClub=MAT.numClubExt and STA.refChamp=MAT.refChamp and MAT.numClubDom=".$ndom."
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch."),
 
nbBc=nbBc+(select MAT.scoreDom from tab_match MAT
	       where STA.numClub=MAT.numClubExt and STA.refChamp=MAT.refChamp and MAT.numClubDom=".$ndom."
and MAT.numJournee=".$njour."
and MAT.refChamp=".$refch.")";