Utiliser des cases pour un systeme horaire H.C et H.P
xunil2003
Messages postés
766
Date d'inscription
Statut
Membre
Dernière intervention
-
xunil2003 Messages postés 766 Date d'inscription Statut Membre Dernière intervention -
xunil2003 Messages postés 766 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Pour gérer des heures H.C et H.P, j'ai fait des cases mais ça marche pas, il m'affiche toujours 23 heures , la dernière case ?
Il affiche :
Comment faut il faire ?
Merci.
Pour gérer des heures H.C et H.P, j'ai fait des cases mais ça marche pas, il m'affiche toujours 23 heures , la dernière case ?
$heure = date("H:i");
echo "heure : $heure";
// Vérifie si on est en H.C ou H.P.
switch($heure)
{
case 00:
$tarif_horaire = HC ;
echo "Minuit --> HC <br>" ;
break;
case 1:
$tarif_horaire = HC ;
echo "1 --> HC <br>" ;
break;
case 2:
$tarif_horaire = HC ;
echo "2 --> HC <br>" ;
break;
case 3:
$tarif_horaire = HC ;
echo "3 --> HC <br>" ;
break;
case 4:
$tarif_horaire = HC ;
echo "4 --> HC <br>" ;
break;
case 5:
$tarif_horaire = HC ;
echo "5 --> HC <br>" ;
break;
case 6:
$tarif_horaire = HP ;
case 7:
$tarif_horaire = HP ;
case 8:
$tarif_horaire = HP ;
case 9:
$tarif_horaire = HP ;
case 10:
$tarif_horaire = HP ;
case 11:
$tarif_horaire = HP ;
case 12:
$tarif_horaire = HP ;
case 13:
$tarif_horaire = HP ;
case 14:
$tarif_horaire = HP ;
case 15:
$tarif_horaire = HP ;
case 16:
$tarif_horaire = HP ;
case 17:
$tarif_horaire = HP ;
case 18:
$tarif_horaire = HP ;
case 19:
$tarif_horaire = HP ;
case 20:
$tarif_horaire = HP ;
case 21:
$tarif_horaire = HP ;
case 22:
$tarif_horaire = HP ;
case 23 :
$tarif_horaire = HC ;
echo "23 --> HC <br>" ;
break;
}
switch($tarif_horaire)
{
case "HC" :
$kwh_c=$contenu_domo ;
break;
case "HP" :
$kwh_p=$contenu_domo ;
break;
}
echo "tarif_horaire : $tarif_horaire";
echo "<br> " ;
Il affiche :
heure : 22:30
23 --> HC
tarif_horaire : HC
Comment faut il faire ?
Merci.
1 réponse
-
Bonjour,
Pour ceux qui son intéressé.
J'ai modifié le système des cases en fonction de l'heure, cette ça marche.
// Vérifie si on est en hc ou hp.
switch($heure)
{
case 00:
$tarif_horaire = HC ;
break;
case 1:
$tarif_horaire = HC ;
break;
case 2:
$tarif_horaire = HC ;
break;
case 3:
$tarif_horaire = HC ;
break;
case 3:
$tarif_horaire = HC ;
break;
case 3:
$tarif_horaire = HC ;
break;
case 5:
$tarif_horaire = HP ;
break;
case 6:
$tarif_horaire = HP ;
break;
case 7:
$tarif_horaire = HP ;
break;
case 8:
$tarif_horaire = HP ;
echo "tarif_horaire : 8 --> HP <br>" ;
break;
case 9:
$tarif_horaire = HP ;
echo "tarif_horaire : 9 --> HP <br>" ;
break;
case 10:
$tarif_horaire = HP ;
echo "tarif_horaire : 10 --> HC <br>" ;
break;
case 11:
$tarif_horaire = HP ;
break;
case 12:
$tarif_horaire = HP ;
break;
case 13:
$tarif_horaire = HP ;
break;
case 14:
$tarif_horaire = HP ;
break;
case 15:
$tarif_horaire = HP ;
break;
case 16:
$tarif_horaire = HP ;
break;
case 17:
$tarif_horaire = HP ;
break;
case 18:
$tarif_horaire = HP ;
break;
case 19:
$tarif_horaire = HP ;
break;
case 20:
$tarif_horaire = HP ;
break;
case 21:
$tarif_horaire = HP ;
break;
case 22:
$tarif_horaire = HP ;
break;
case 23:
$tarif_horaire = HC ;
echo "tarif_horaire : 23 --> HC <br>" ;
break;
default:
echo "tarif_horaire : default <br>" ;
break;
}
switch($tarif_horaire)
{
case HC :
$kwh_c = $contenu ;
case HP :
$kwh_p = $contenu ;
}
Et je l'ai remodifié pour faire plus simple.
//$Nombre = $heure;
$Nombre = 7;
echo $Nombre;
switch ($Nombre)
{
case (($Nombre >= 7) && ($Nombre <= 22)) :
$tarif_horaire = HP;
echo "Tarif_horaire : 7H - 23H --> HP <br>";
break;
case (($Nombre <= 23) && ($Nombre >= 6)) :
$tarif_horaire = HC;
echo "Tarif_horaire : 23H - 7H --> HC <br>";
break;
default:
echo "tarif_horaire : default <br>" ;
break;
}
switch($tarif_horaire)
{
case HC :
$kwh_c = $contenu ;
case HP :
$kwh_p = $contenu ;
}
Merci.