Bonjour à tous,

J'ai crée un script en php qui calculant le pourcentage.

Voici mon script :

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
 
$result = pg_query($db, "SELECT KBarticleID, pourcentage_valide, pourcentage_invalide FROM $graphe WHERE date_ajout='$date' AND unite='$division'");
if (!$result)
{
  echo "Une erreur s'est produite.\n";
  exit;
}
 
$KBarticleID = array();
$pourcentage_valide = array();
$pourcentage_invalide = array();
$resultat_valide = array();
$resultat_valide_final = array();
 
while($row = pg_fetch_assoc($result))
{
        $KBarticleID[] = $row['KBarticleID'];
        $pourcentage_valide[] = $row['pourcentage_valide'];
        $pourcentage_invalide[] = $row['pourcentage_invalide'];
        $resultat_valide = $row['pourcentage_valide']/$row['pourcentage_valide']+$row['pourcentage_invalide'];
        $resultat_valide_final=$resultat_valide*100;
        echo $resultat_valide_final;
}
Voici ma table :

kbarticleid | pourcentage_valide | pourcentage_invalide
-------------+--------------------+-------------------
973540 | 0 | 0 |
973540 | 7 | 0 |
973507 | 0 | 0 |
973507 | 7 | 0 |
973354 | 0 | 0 |
973354 | 7 | 0 |
973346 | 14 | 0 |
973346 | 696 | 0 |

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
$row['pourcentage_valide']/$row['pourcentage_valide']+$row['pourcentage_invalide'];
$resultat_valide_final=$resultat_valide*100;
Donc voici le calcul :

Si je fais (0 + 0)/0 c'est impossible.
Par contre ce que je voudrais obtenir dans ce cas c'est 100% pour pourcentage valide et pourcentage_invalide 0

Est-ce-que pouvez-vous m'aider ?

Cordialement,