У меня проблемы с выполнением простых математических операций (которые станут более сложными) в динамической таблице.Каждый раз, когда я отправляю результаты, он должен суммировать и сохранять общий счет в $ Players [$ player] ['Score'], однако после его циклирования, когда он снова сбрасывается до нуля.
Любые идеи, куда я идунеправильно?
$new_players = $_SESSION["players"];
//$_SESSION["players"] - brings in array an array like following
/* array (size=1)
'John' =>
array (size=3)
'previous' => int 0
'score' => int 0
'hand' => int 0 */
if (empty($players)) {//added as i thought $new_players = $_SESSION["players"]; might be blanking scores
$players = $new_players;
}
if (isset($_POST[$submit])) {
$new_array = $_POST['player'];
foreach ($players as $player =>$i) {
$players[$player]['hand'] = $new_array[$player]+0;//add to convert the $new_array[$player] to int
$players[$player]['previous'] = $players[$player]['hand'];
$players[$player]['score'] = $players[$player]['score'] + $players[$player]['hand'];
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="formAcc">
<ul style= "text-align: center">
<article>
<li>
<label>Current Standing</label>
<?php
echo '<table id="db_results">
<colgroup>
<col class="col15" />
<col class="col15" />
<col class="col15" />
<col class="col15" />
</colgroup>
<tr>
<th>Name</th>
<th>Previous Score</th>
<th>Current Score</th>
<th>Hand</th>
</tr>';
foreach ($players as $player =>$i) {
echo "<tr class=\"center\">
<td>". $player . "</td>
<td>". $i['previous'] . "</td>
<td>". $i['score'] . "</td>"
. '<td><input type="text" name="player['.$player.']" value="0"/></td>
</tr>';
}
echo "</table>";
?>
<input type="submit" name="<?php echo $submit?>" value="Input Scores" style="margin-top: 5px;"/>
</li>
</article>
</ul>
</form>