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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| <?php
$moyenne = 0 ;
// r?p?tion variable formulaire
if(isset($_POST['note'])) {
// recupere la somme
$resultat = $_POST['note'];
$somme = 0;
$count = 0;
foreach ($resultat as $valeur) {
if(!empty($valeur)){
$somme += $valeur; // Ou $somme = $somme + $valeur;
$count += 1;
}
}
$moyenne = $somme/$count;
?>
<?php
}
?>
<?php
$matiere = [
"math" => ["value" => 0, "label" => "Mathématiques"],
"francais" => ["value" => 0, "label" => "Français"],
"espagnol" => ["value" => 0, "label" => "Espagnol"],
"eco" => ["value" => 0, "label" => "Economie"],
"phychim" => ["value" => 0, "label" => "Physique-chimie"],
"art" => ["value" => 0, "label" => "Art-plastique"],
"music" => ["value" => 0, "label" => "Musique"]
];
foreach ($_POST as $index=>$matiere) {
if (!empty ($matiere [$index]) {
$erreur = "Attention dans le calcul de la moyenne il manque la ou les notes pour les UE suivantes : X - Y - Z ";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h4> FORMULAIRE CALCUL D'UNE MOYENNE </h4>
<form method = "post" >
<table>
<tr>
<th>
<label for ="note1" > Mathematiques : </label> <input type="number" name="note[]" id="note1" value="<?php if(isset($_POST['note1[]'])) { echo htmlentities($_POST['note1[]']);}?>"/> </br> </br>
</th>
</tr>
<tr>
<th>
<label for ="note2" > Francais : </label> <input type="number" name="note[]" id="note2" > </br> </br>
</th>
</tr>
<tr>
<th>
<label for ="note3"> Espagnol : </label> <input type="number" name="note[]" id="note3" > </br> </br>
</th>
</tr>
<tr>
<th>
<label for ="note4" > Economie : </label> <input type="number" name="note[]" id="note4"> </br> </br>
</th>
</tr>
<tr>
<th>
<label for ="note5" > Physique-chimie: </label> <input type="number" name="note[]" id="note5" > </br> </br>
</th>
</tr>
<tr>
<th>
<label for ="note6" > Art-plastique : </label> <input type="number" name="note[]" id="note6" > </br> </br>
</th>
</tr>
<tr>
<th>
<label for ="note7" > Musique </label> <input type="number" name="note[]" id="note7" > </br> </br>
</th>
</tr>
<tr>
<th>
<input type=submit value="Calculer la moyenne" ></input></br> </br>
MOYENNE GENERALE : <input type="text" value="<?php echo $moyenne;?> /20">
</th>
</tr>
</form>
</body>
</html> |
Partager