This is only my second project so very new so excuse my scrappy code. I’m trying to generate a table from MySQL with an additional input column. This column is where I want to be able to input a number which will be added to the original MySQL table ‘score’ if that makes sense. The table is DROPPED and CREATED every time a new game starts (not hand) due to different players participating. The inputs for each hand could happen up to 50 times before the table is dropped. See the code might make more sense or not. Should be simple I just can’t get my head round it at the moment.
<?php // defined variables to remove errors
$submit = 'add_scores';
$name = $message = "";
$hand = 0;
$array = $index = "";
$datatable = "cards_players"; // MySQL table name
?>
<?php
if (isset($_POST[$submit])) {
//this is where my insert statement will go
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="formAcc">
<ul style= "text-align: center">
<article>
<li>
<label>Current Standing</label>
<?php
$datatable = "cards_data"; // MySQL table name
$sql = "SELECT * FROM ".$datatable." WHERE player IS not NULL ORDER BY id ASC";
$rs_result = $connection->query($sql);
// Check connection
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
?>
<?php
echo '<table id="db_results">
<colgroup>
<col class="col15" />
<col class="col15" />
<col class="col15" />
<col class="col20" />
</colgroup>
<tr>
<th>Name</th>
<th>Previous Score</th>
<th>Current Score</th>
<th>This Hand</th>
</tr>';
while($row = $rs_result->fetch_assoc()) {
echo "<tr class=\"center\">
<td>". $row["player"] . "</td>
<td>". $row["previous_score"] . "</td>
<td>". $row["score"] . "</td>
<td>"//. retain_fill ('text','hand','',$hand,'0') ."
. '<input type="text" name="'.$row["player"].'" placeholder="';
if (!empty($hand)) {echo $hand. '" value="'.$hand.'"/>';
}
else {echo 0 . '" value=""/>';}
"</td>
</tr>";
}
echo "</table>";
?>
</li>
<li>
<input type="submit" name="<?php echo $submit?>" value="Input Scores" style="margin-top: 5px;"/>
At the moment I'm not even sure how to begin the insert statement for each user as I know this will be a loop of some sort. Any help appreciated :-)