[RESOLU] Conditions non prises en compte

Petit nouveau ! | 2 Messages

12 mars 2016, 20:20

Bonjour,

je développe un calculateur de points pour un site de tennis de table, et certaines conditions ne sont pas prises en compte, je ne trouve pas pourquoi.

En gros, tout ce qui se trouve après les ":" n'est pas pris en compte.
Si vous testez, tout fonctionne sauf lorsque l'adversaire a plus de points que le joueur au départ, ce qui correspond au nombre après les ":"

Calculateur visible à cette adresse : http://zone2.gixia.fr/index.php/calculateur

Merci d'avance

Morceau de code :
if ($diff >= 0 && $diff <= 24) {
		$gain = $startPoint >= $enemyPoint ? 6 : 6;
	}
Code total :
<div id="calculateur">
<form action="http://zone2.gixia.fr/index.php/calculateur" method="POST">
<p><label>Vos points : <input type="text" name="startPoint" /></label></p>
<p><label>Points adversaire : <input type="text" name="enemyPoint" /></label></p>
<p><label>Victoire : 
<input type="radio" name="victoire" value="oui" checked="checked" /> <label for="oui">Oui</label>
<input type="radio" name="victoire" value="non" /> <label for="non">Non</label></p>
<p><label>Coefficient : 
<input type="radio" name="coef" value="0.5" /> <label for="0.5">0.5</label>
<input type="radio" name="coef" value="0.75" /> <label for="0.5">0.75</label>
<input type="radio" name="coef" value="1" checked="checked" /> <label for="0.5">1</label>
<input type="radio" name="coef" value="1.25" /> <label for="0.5">1.25</label>
<input type="radio" name="coef" value="1.50" /> <label for="0.5">1.50</label>
</p>
<p><input type="submit" value="Calculer" /></p>
</form>
<?php
$victoire = $_POST['victoire'];
$startPoint = $_POST['startPoint'];
$enemyPoint = $_POST['enemyPoint'];
$diff = $startPoint - $enemyPoint;

if ($victoire == "oui") {

	if ($diff >= 0 && $diff <= 24) {
		$gain = $startPoint >= $enemyPoint ? 6 : 6;
	}
	if ($diff >= 25 && $diff <= 49) {
		$gain = $startPoint >= $enemyPoint ? 5.5 : 7;
	}
	if ($diff >= 50 && $diff <= 99) {
		$gain = $startPoint >= $enemyPoint ? 5 : 8;
	}
	if ($diff >= 100 && $diff <= 149) {
		$gain = $startPoint >= $enemyPoint ? 4 : 10;
	}
	if ($diff >= 150 && $diff <= 199) {
		$gain = $startPoint >= $enemyPoint ? 3 : 13;
	}
	if ($diff >= 200 && $diff <= 299) {
		$gain = $startPoint >= $enemyPoint ? 2 : 17;
	}
	if ($diff >= 300 && $diff <= 399) {
		$gain = $startPoint >= $enemyPoint ? 1 : 22;
	}
	if ($diff >= 400 && $diff <= 499) {
		$gain = $startPoint >= $enemyPoint ? 0.5 : 28;
	}
	if ($diff >= 500) {
		$gain = $startPoint >= $enemyPoint ? 0 : 40;
	}

}

	
elseif ($victoire == "non") {
	
	if ($diff >= 0 && $diff <= 24) {
		$gain = $startPoint <= $enemyPoint ? -5 : -5;
	}
	if ($diff >= 25 && $diff <= 49) {
		$gain = $startPoint <= $enemyPoint ? -4.5 : -6;
	}
	if ($diff >= 50 && $diff <= 99) {
		$gain = $startPoint <= $enemyPoint ? -4 : -7;
	}
	if ($diff >= 100 && $diff <= 149) {
		$gain = $startPoint <= $enemyPoint ? -3 : -8;
	}
	if ($diff >= 150 && $diff <= 199) {
		$gain = $startPoint <= $enemyPoint ? -2 : -10;
	}
	if ($diff >= 200 && $diff <= 299) {
		$gain = $startPoint <= $enemyPoint ? -1 : -12.5;
	}
	if ($diff >= 300 && $diff <= 399) {
		$gain = $startPoint <= $enemyPoint ? -0.5 : -16;
	}
	if ($diff >= 400 && $diff <= 499) {
		$gain = $startPoint <= $enemyPoint ? 0 : -20;
	}
	if ($diff >= 500) {
		$gain = $startPoint <= $enemyPoint ? 0 : -29;
	}
}

$coef = $_POST['coef'];
$endWin = $gain * $coef;
$endScore = $startPoint + $endWin;

if (isset($startPoint)) {
?>
<table>
<tr>
<td>Points adversaire</td>
<td>Victoire</td>
<td>Gain brut</td>
<td>Coef.</td>
<td>Gain calculé</td>
</tr>
<tr>
<td><?php echo $_POST['enemyPoint'] ?></td>
<td><?php echo $_POST['victoire'] ?></td>
<td><?php 
if ($gain > 0) {echo '<span class="vert">+' . $gain . '</span>';}
elseif ($gain < 0) {echo '<span class="rouge">' . $gain . '</span>';}
elseif ($gain < 0) {echo $gain;}
?></td>
<td><?php echo $coef ?></td>
<td><?php
if ($endWin > 0) {echo '<span class="vert">+' . $endWin . '</span>';}
elseif ($endWin < 0) {echo '<span class="rouge">' . $endWin . '</span>';}
elseif ($endWin < 0) {echo $endWin;}
?></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><?php
if ($endWin > 0) {echo '<span class="vert">Total Gagné :</span>';}
elseif ($endWin < 0) {echo '<span class="rouge">Total Perdu :</span>';}
elseif ($endWin < 0) {echo 'Total :';}
?></td>
<td><?php
if ($endWin > 0) {echo '<span class="vert">+' . $endWin . '</span>';}
elseif ($endWin < 0) {echo '<span class="rouge">' . $endWin . '</span>';}
elseif ($endWin < 0) {echo $endWin;}
?></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>Score actuel :</td>
<td><?php
if ($endScore > 0) {echo '<span class="vert">' . $endScore . '</span>';}
elseif ($endScore < 0) {echo '<span class="rouge">' . $endScore . '</span>';}
elseif ($endScore < 0) {echo $endScore;}
?></td>
</tr>
</table>
<?php } ?>
<p>Calculateur de points tenis de table du site <a href="http://ping-pong.sport">www.ping-pong.sport</a> developpé par <a href="https://www.gixia.fr">Gixia</a>
</div>

Mammouth du PHP | 2703 Messages

12 mars 2016, 20:52

j'ai testé le code suivant, et cela a bien affiché le résultat escompté :
$startPoint = 1;
$enemyPoint = 2;
$gain = $startPoint >= $enemyPoint ? 5.5 : 7;
echo "$gain<br>";
$startPoint = 2;
$enemyPoint = 1;
$gain = $startPoint >= $enemyPoint ? 5.5 : 7;
echo "$gain<br>";

Petit nouveau ! | 2 Messages

12 mars 2016, 20:57

C'est tout con en fait
if ($diff >= 0 && $diff <= 24)
Ne passe par car si l'adversaire a plus de points, diff sera < 0

Remplacé par
if ($diff <= 24)