我是 PHP 新手,整天都在努力解决这个问题。我有一个包含玩家详细信息的 MySQL 数据库。我想从数据库中选择它们并以表格的形式显示在表格中,这适用于下面的代码。
当我想更新行时,问题就出现了,可能是使用选项字段将播放器状态从活动状态变为非活动状态。当我按下提交时,我可以获得每个 pdbactive 字段的值 OK,但我无法获得 PID,这是对数据库进行更新的关键。
<form name="selected_players" action="" method="POST">
<table border="1">
<th>Player ID</th>
<th>Player Name</th>
<th>Player Surname</th>
<th>Status</th>
<th>Primary Team*</th>
<?php
// Then get the players from the players table who have got same team_name but no team_id yet....which would have be set if they were active
$query = "select * from `player2012` where teamid ='$tid' and aru='A';";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$count = mysql_num_rows($result);
echo $count;
//echo ("<br />");
while ($row = mysql_fetch_assoc($result)) {
$player_id = $row["player_id"];
$player_fname = $row["player_fname"];
$player_sname = $row["player_sname"];
$pactive = $row["active"];
//echo ($pactive);
//echo ("<br />");
?>
<tr>
<td><input name"pid[]" id="pid[]" type="text" value="<?php echo $player_id ?>" /><?php echo $player_id ?></td>
<td><input name"player_fn[]" type="hidden" value="<?php echo $player_fname ?>" /><?php echo $player_fname ?></td>
<td><input name"player_sn[]" type="hidden" value="<?php echo $player_sname ?>" /><?php echo $player_sname ?></td>
<?php if($pactive=="1"){
?>
<td><select name="pdbactive[]" id="pdbactive[]">
<option value="1" selected="selected">Active</option>
<option value="0">Not Active</option>
</td>
<?php }
else
{
?>
<td><select name="pdbactive[]" id="pdbactive[]">
<option value="1">Active</option>
<option value="0" selected="selected">Not Active</option>
</td>
<?php
}
?>
<td>
</td>
</tr>
<?php
}
?>
</table>
<p> </p>
<p> When you have updated "status" for each of these players, please press submit button
<input name="Submit" type="submit" id="Sumbit" value="Submit" /> </p>
</form>
<?php
mysql_free_result($result);
//if form has been pressed proccess it
if($_POST["Submit"])
{
//get data from form
$ractive = $_POST['pdbactive'];
$rid= $_POST['pid'];
for($i=0;$i<$count;$i++){
echo ($i);
echo ("<br />");
$stat=($ractive[$i]);
$idd=($rid[$i]);
$sql_insert="UPDATE 'player2012' SET active='$stat' where id='$idd'";
print($sql_insert);
echo ("<br />");
}
}
?>
目前我只想创建 SQL 语句,以便在开始更新数据库之前知道它可以工作。所以所有的回声和打印只是我试图找出答案
帮助!!!!!!!!!!!!!!