J'ai actuellement une variable $test qui tourne dans une boucle et qui change à chaque enregistrement de mission d'un joueur je voudrais pouvoir afficher un décompte différents pour chaque variable mise à jour.
Mon code PHP
echo "<table border=\"0\" width=\"330px\" cellspacing=\"0\" cellpadding=\"0\">\n"
. "<script type=\"text/javascript\" src=\"modules/Mission/mission.js\"></script>\n"
. "<tr height=\"20px\">\n"
. "<td colspan=\"3\" class=\"text\" align=\"center\">PROCHAINES MISSIONS</td></tr></table></br >\n";
function js_popup($w = 1600, $h = 900){
echo "<script type=\"text/javascript\">\n"
. "<!--\n"
. "function openWin(id,d,m,y){\n"
. "w = window.open('index.php?file=Mission&nuked_nude=index&op=show_event&eid='+id+'&d='+d+'&m='+m+'&y='+y,'event'+id,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" . $w . ",height=" . $h . ",top=30,left=30');\n"
. "}\n"
. "// -->\n"
. "</script>";
}
$d = date("d");
$m = date("m");
$y = date("Y");
while (list($mission_id, $etat, $createur, $date_creation, $simulateur, $titre, $type, $theatre, $d, $m, $y, $heure_debut, $minute_debut, $report, $nbf16, $nbf18, $nbm2000, $nbawacs, $inscritf16, $inscritf18, $inscritm2000, $inscritawacs, $placedispo) = mysql_fetch_array($sql2))
{
$titre = nkHtmlEntities($titre);
$theatre = nkHtmlEntities($theatre);
///////////////////////////////////
// BMS //
//////////////////////////////////
if ($m < 10)
{
$m = "0" .$m;
}
if ($d < 10)
{
$d = "0" .$d;
}
if ($heure_debut < 10)
{
$heure_debut = "0" .$heure_debut;
}
if ($minute_debut < 10)
{
$minute_debut = "0" .$minute_debut;
}
$test = $y . "/" .$m ."/" .$d ." " . $heure_debut . ":" . $minute_debut;
$date = $d . "/" .$m ."/" .$y;
$heure = "" . $heure_debut . "h" . $minute_debut . "";
if ($nbf16 > 0){$avion1 = "F-16";} else {$avion1 = "";}
if ($nbf18 > 0){$avion2 = "F-18";} else {$avion2 = "";}
if ($nbm2000 > 0){$avion3 = "M-2000";} else {$avion3 = "";}
if ($nbawacs > 0){$avion4 = "AWACS";} else {$avion4 = "";}
$avion = " " . $avion1 . " " . $avion2 . " " . $avion3 . " " . $avion4 . " \n";
$restedispo = $inscritf16 + $inscritf18 + $inscritm2000 + $inscritawacs;
echo "<br /><table border=\"0\" width=\"330px\" cellspacing=\"0\" cellpadding=\"0\">\n"
. "<script type=\"text/javascript\" src=\"modules/Mission/mission.js\"></script>\n"
. "<tr height=\"20px\">\n"
. "<td colspan=\"3\" class=\"title3\" align=\"left\">" . $type . " " . $titre . "\n";
?>
<div id="compte_a_rebours" style="font-size: 20px; font-family: Conv_stenc_ex"></div>
<script type="text/javascript">
var target = '<?php echo $test; ?>';
</script><?php
echo "<script type=\"text/javascript\" src=\"modules/Mission/compteur.js\"></script>\n";
echo "</td></tr>\n"
. "<tr height=\"20px\">\n"
. "</tr>\n"
. "<tr height=\"50px\">\n"
. "<td rowspan=\"2\" align=\"left\" width=\"50px\"><img src=\"modules/Mission/images/bmsm.jpg\" alt=\"\" /></td>\n"
. "<td rowspan=\"2\" align=\"center\" width=\"140px\" height=\"50px\"><b>" . $date . "</b>\n"
. "<br /><b>" . $heure . "</b></td>\n"
. "<td rowspan=\"2\" align=\"center\" width=\"140px\"><a href=\"javascript:openWin( '" . $mission_id . "', '" . $d . "', '" . $m . "', '" . $y . "')\"><img src=\"modules/Mission/images/inscription.png\" alt=\"Inscription\" title=\"Je m'inscris\"/></a></td>\n"
. "<tr>\n"
. "<tr>\n"
. "<td colspan=\"3\" align=\"left\"><small>Dispo:</small> <span style='color:#8B0000;'><small>" . $avion . "</small></span></td>\n"
. "</tr>\n"
. "<td colspan=\"3\" align=\"left\"><small>Pilote inscrit:</small> " . $restedispo . "/" . $placedispo . "</td></tr></table>\n";
}
js_popup();
Et mon code javascriptfunction compte_a_rebours()
{
var compte_a_rebours = document.getElementById("compte_a_rebours");
var date_actuelle = new Date();
var date_evenement = new Date(target);
var total_secondes = (date_evenement - date_actuelle) / 1000;
var prefixe = "dans ";
if (total_secondes < 0)
{
prefixe = "Vol en cours depuis "; // On modifie le préfixe si la différence est négatif
total_secondes = Math.abs(total_secondes); // On ne garde que la valeur absolue
}
if (total_secondes > 0)
{
var jours = Math.floor(total_secondes / (60 * 60 * 24));
var heures = Math.floor((total_secondes - (jours * 60 * 60 * 24)) / (60 * 60));
minutes = Math.floor((total_secondes - ((jours * 60 * 60 * 24 + heures * 60 * 60))) / 60);
secondes = Math.floor(total_secondes - ((jours * 60 * 60 * 24 + heures * 60 * 60 + minutes * 60)));
var et = "et";
var mot_jour = "j";
var mot_heure = "h";
var mot_minute = "m";
var mot_seconde = "s";
if (jours == 0)
{
jours = '';
mot_jour = '';
}
else if (jours == 1)
{
mot_jour = "j";
}
if (heures == 0)
{
heures = '';
mot_heure = '';
}
else if (heures == 1)
{
mot_heure = "h";
}
if (minutes == 0)
{
minutes = '';
mot_minute = '';
}
else if (minutes == 1)
{
mot_minute = "m";
}
if (secondes == 0)
{
secondes = '';
mot_seconde = '';
et = '';
}
else if (secondes == 1)
{
mot_seconde = "s";
}
if (minutes == 0 && heures == 0 && jours == 0)
{
et = "";
}
compte_a_rebours.innerHTML = prefixe + jours + ' ' + mot_jour + ' ' + heures + ' ' + mot_heure + ' ' + minutes + ' ' + mot_minute + ' ' + secondes + ' ' + mot_seconde;
}
else
{
compte_a_rebours.innerHTML = 'Le vol est en cours.';
}
var actualisation = setTimeout("compte_a_rebours();", 1000);
}
compte_a_rebours();
Et voici ce que j'ai besoin, on ne voit qu'un compteur qui prend la valeur du dernier enregistrement.