Bonjour à tous,
Suite à plusieurs tentatives sans résultats je fait appel à votre aide.
Explications :
Je suis en train de créer un site web (Jeux sur navigateur) et dans le tableau de bord des joueurs j'aimerai afficher, dans un tableau, les différents bâtiments qui sont en court d'amélioration avec le temps restant qui s'affiche dynamiquement via un script Javascript.
Mon problème est que le temps s'affiche uniquement un seul fois quand j'ai plusieurs améliorations en court et le temps diminue 2 secondes par 2 secondes. Voir l'image ci-dessous.
Code HTML : 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 <table> <tr> <th colspan=2>Amélioration en cour</th> </tr> <tr> <th>Nom du bâtiment</th> <th>Temps</th> </tr> <?php $EncourAmelioration = $DB->query('SELECT * FROM ConstructionBat WHERE idjoueur = "'. $id_joueur .'"'); while ($EncourAmelioration1 = $EncourAmelioration->fetch()) { $infoBat = $DB->query('SELECT * FROM Batiments WHERE id_bat = "'.$EncourAmelioration1['id_batiment'].'"' ); $infoBat1 = $infoBat->fetch(); //Calcul du temps d'amélioration restant $temps = intval(time()); $CalculTempsConstruction = $temps - $EncourAmelioration1['debut_construction']; $dateMySQL = $EncourAmelioration1['temps_construction'] - $CalculTempsConstruction; // Calcul du temps de construction $t = $EncourAmelioration1['temps_construction'] ; $s=$t%60; $t=($t-$s)/60; $m=$t%60; $h=($t-$m)/60; if($m<10){$m="0".$m;} if($s<10){$s="0".$s;} ?> <script type="text/javascript"> var tps = <?php echo $dateMySQL; ?>; var h= 0; var m= 0; var s= 0; var disp=""; var idtimer =setInterval('affichetemps()',1000); function affichetemps(){ tps-- ; h = parseInt(tps/3600) ; m = parseInt((tps%3600)/60) ; s = parseInt((tps%3600)%60) ; disp = (h<10 ? "0"+h : h) + ' h ' + (m<10 ? "0"+m : m) + ' min ' + (s<10 ? "0"+s : s) + ' sec '; document.getElementById('<?php echo $EncourAmelioration1['id_batiment']; ?>').innerHTML= disp; if ((h <= 0 && s <= 0 && m <=0)) { clearInterval(idtimer); url="http://www.streaming-world.fr/NewsSite/Modules/Batiments/fin_amelioration.php?id_batiment=<?php echo $id_bat; ?>&nommysql=<?php echo $info_batiments1['nom_mysql']; ?>&NomBat=<?php echo $NomBat; ?>&joueur=<?php echo $id_joueur; ?>&nivo=<?php echo $nivo; ?>&fichier=<?php echo $info_batiments1['fichier']; ?>" // Changer ici l'url Go(url) } } function Go(url) { //window.status="Go !" //document.s.Time.value="Go !" setTimeout("window.location=url", 400) } </script> <tr> <td> <?php echo $infoBat1['nom']; ?> </td> <td> <span style='color: green;'> <div id="<?php echo $EncourAmelioration1['id_batiment']; ?>" style="font-family: arial; size: 60px;"> </div></span> </td> </tr><?php } ?> </table>
Avez-vous une idée??
Partager