您好,我是PHP的新手
我有这个问题:
我想从表单中发布多项选择+隐藏字段:
<?php
if (isset($_SESSION['nickname']))
{
$result = mysql_query("SELECT * FROM users");
$teamsCount = ceil(mysql_num_rows($result)/2);
for ($i=1; $i<=$teamsCount; $i++)
{
// TEST: echo $i . " TeamsCount er: " . $teamsCount. "<br>";
?>
Team <? echo $i; ?>
<form name="addTeam" action="buildTeams.php" method="POST">
<input type="hidden" name="hiddenField" value="<?php $i; ?>" />
<select name="teams[]" multiple="multiple" size="<?php echo mysql_num_rows($result); ?>">
<?php
$query = mysql_query("SELECT * FROM users");
while ($row=mysql_fetch_array($query))
{
$id=$row["ID"];
$nick=$row["Nick"];
?>
<option value="<?php echo $id; ?>"><?php echo ucfirst($nick); ?></option>
<?php
}
?>
</select>
<input type="submit" value="Make them teams!!" />
</form>
<?php
}
}
?>
答案 0 :(得分:3)
我认为你在这一行中有错误:
<input type="hidden" name="hiddenField" value="<?php $i ?>" />
应该是
<input type="hidden" name="hiddenField" value="<?php echo $i ?>" />
编辑:
将团队ID放在选择名称中。例如:
<select name="teams[<?=$i?>][]">
在PHP中执行:
foreach ($_POST['teams'] as $team_id => $choices)
答案 1 :(得分:0)
我认为您应该检查$_POST['hiddenField']
以获取隐藏价值