Like some of those responses in the other thread, if you create a form for each of those “deal cells”, which holds an input for both the record id and the “deal field” name, then only one “deal field” name is sent on POST. Something like this.
<form action="" method="post">
<button class="btn btn-default" type="submit" name="SelectDeal">1st Deal</button>
<input type="hidden" name="record_id" value="' .$row['id']. '"/>
<input type="hidden" name="1stdeal" value="1"/>
</form>
You then have a logical IF statement saying IF Not Empty 1stdeal THEN value is 1 else value is 0. You could set each name to a variable using these conditions.
$deal1st = (!empty($_POST['1stdeal']) ? 1 : 0);
$deal2nd = (!empty($_POST['2nddeal']) ? 1 : 0);
$deal3rd = (!empty($_POST['3rddeal']) ? 1 : 0);
Then all that is left is wrapping it all up within a form submission condition check using the button name and also checking that the record ID is not empty as you will use this to identify the record to update.
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['SelectDeal']) && !empty($_POST['record_id'])):
endif;
As a bonus, if you wanted to show a button color based on the values in the database you could set avariable to echo a CLASS name or an inline style tag. Here’s an example of inline style type, which adds a green background color to records with a value of 1.
$selected_1stdeal = (!empty($row['1stdeal']) ? ' style="background-color:#92CC58"' : '');
$selected_2nddeal = (!empty($row['2nddeal']) ? ' style="background-color:#92CC58"' : '');
$selected_3rddeal = (!empty($row['3rddeal']) ? ' style="background-color:#92CC58"' : '');
Putting it all together you would have this.
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['SelectDeal']) && !empty($_POST['record_id'])):
$deal1st = (!empty($_POST['1stdeal']) ? 1 : 0);
$deal2nd = (!empty($_POST['2nddeal']) ? 1 : 0);
$deal3rd = (!empty($_POST['3rddeal']) ? 1 : 0);
$sql_update_deal = "UPDATE `scores` SET
`1stdeal` = ?
,`2nddeal` = ?
,`3rddeal` = ?
WHERE `id` = ?";
$query_update_deal = $connect->prepare($sql_update_deal);
$query_update_deal->bind_param("iiii", $deal1st, $deal2nd, $deal3rd, $_POST['record_id']);
$query_update_deal->execute();
endif;
$sqlQuery = "SELECT * FROM scores";
$qry = $connect->query($sqlQuery);
echo '<table class="greyGridTable">
<tr>
<th>Name</th>
<th>1st Call</th>
<th>FO</th>
<th>OPPT</th>
<th>1st Deal</th>
<th>2nd Deal</th>
<th>3rd Deal</th>
</tr>'."\r";
while($row = $qry->fetch_assoc()){
$selected_1stdeal = (!empty($row['1stdeal']) ? ' style="background-color:#92CC58"' : '');
$selected_2nddeal = (!empty($row['2nddeal']) ? ' style="background-color:#92CC58"' : '');
$selected_3rddeal = (!empty($row['3rddeal']) ? ' style="background-color:#92CC58"' : '');
echo '<tr class="'. $color .' lighten-2">
<td>'.$row['Name'].'</td>
<td>'.$row['1stcall'].'</td>
<td>'.$row['FO'].'</td>
<td>'.$row['OPPT'].'</td>
<td>
<form action="" method="post">
<button class="btn btn-default" type="submit" name="SelectDeal"'.$selected_1stdeal.'>1st Deal</button>
<input type="hidden" name="record_id" value="' .$row['id']. '"/>
<input type="hidden" name="1stdeal" value="1"/>
</form>
</td>
<td>
<form action="" method="post">
<button class="btn btn-default" type="submit" name="SelectDeal"'.$selected_2nddeal.'>2nd Deal</button>
<input type="hidden" name="record_id" value="' .$row['id']. '"/>
<input type="hidden" name="2nddeal" value="1"/>
</form></td>
<td>
<form action="" method="post">
<button class="btn btn-default" type="submit" name="SelectDeal"'.$selected_3rddeal.'>3rd Deal</button>
<input type="hidden" name="record_id" value="' .$row['id']. '"/>
<input type="hidden" name="3rddeal" value="1"/>
</form></td>
</tr>'."\r";
}
echo '</table>'."\r";