我对 PHP 很陌生,我正在寻找一种将多个复选框的值提交到数据库中的方法!现在我已经设法让复选框显示为选中,如果数据库中的值 = 1,否则它将被取消选中。
以下是我拥有的当前代码。
<?php
$query = "SELECT * FROM users_achievements_xbox WHERE user_id = '$userID' && game_id = '$gameID' ORDER BY achievement_id ASC";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) { // Start looping table row
$userID = $row['user_id'];
$gameID = $row['game_id'];
$achievementID = $row['achievement_id'];
$achievementName = $row['achievement_name'];
$achievementDescription = $row['achievement_description'];
$achievementValue = $row['achievement_value'];
$check = mysql_query("SELECT * FROM users_achievements_xbox WHERE user_id = '$userID' && game_id = '$gameID' && achievement_id = '$achievementID'");
$row2 = mysql_fetch_assoc($check);
$achievement_locked = $row2['achievement_locked'];
if($achievement_locked == "0")
{
$checked = 'checked="checked"';
}
else
{
$checked = "";
}
?>
<tr align="center" bgcolor="#eeeeee">
<td> <img src="images/achievements/<?php echo $gameID; ?>/<?php echo $achievementID; ?>.jpg" /> </td>
<td> <?php echo $achievementName; ?> </td>
<td> <?php echo $achievementDescription; ?> </td>
<td> <?php echo $achievementValue; ?> </td>
<td> <input type="checkbox" name="checkbox" value="0" <?php echo $checked ?> /> </td>
</tr>
<?php
} // end of while loop
?>
我正在考虑尝试通过 isset 执行此操作,但我不想要一个循环的提交按钮" 在我的数据库中,当我只希望选中的复选框在选中时更改为 0,如果不选中则更改为 1!
谢谢你的帮助!