Hello,
I am generating a table with a while loop and also displaying a <select> form in the last table column. My best (yet still feeble attempt) only updates the first row. Doing it another way I was able to update only the last row.
Any help would be appreciated.
<?php
if (isset($_POST["submit"])){
foreach ($_POST['round'] as $id => $round) {
$id = (int)$id;
$round = (int)$round;
$query = "UPDATE keepers SET
round = {$round}
WHERE id = {$id}";
$result = mysql_query($query, $connection) or die(mysql_error());
if (mysql_affected_rows()>= 1){
redirect_to('keepers.php?page=1');
}else{
$message = "The subject update failed.<br />" . mysql_error();
}
}
}
<div>
<table style='width:600px' border='2 px'>
<tr>
<td>Player Name</td>
<td align= "center">Round Availible<br />2012</td>
<td align= "center">Adjust Round</td>
</tr>
<?php
$result = mysql_query("SELECT * FROM keepers
WHERE member_id = {$_SESSION['user_id']} AND keeping = 1",
$connection);
confirm_query($result);?>
?>
<?php
while(list($id,$member_id,$player_name, $a_info,$b_info,$years_kept,$keeping,$round)=mysql_fetch_row($result)){?>
<input name="id[]" type="hidden" value="<?php echo $id?>"/>
<tr>
<td><?php echo $player_name;?></td>
<td align= "center"><?php echo $b_info;?></td>
<td align= "center" ><select name="round[<?php echo $id?>]">
<?php
for($count=1; $count<= $b_info; $count++){
echo "<option value=\"{$count}\"";
if ($b_info== $count){
echo " selected";}
echo ">{$count}</option>";
}} ?></select>
</table>
</div>
<br />
<input type='submit' name='submit' value='Submit' align = 'right'/>
</form>