带注释的表单提供了一系列使用选择表单进行选择的选项。当从$ _POST数组中检索值时,虽然传递了正确的id,但季节的值似乎只是表单中的最后一个值。
我检查了我的代码,据我所知,联盟在其他任何地方都没有更新。
我确定我错过了一些显而易见的东西,但无法弄明白!
<form method = 'post' action = 'index.php?choice=matcht&stage=1'><table width = '50%' border = '1'><thead><tr>
<th>Select</th>
<th>League</th>
<th>Season</th>
</tr></thead>
<tr><td><input type = 'radio' name = 'id' value = '1' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '12' readonly></td>
</tr>
<tr><td><input type = 'radio' name = 'id' value = '25' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '13' readonly></td>
</tr>
<tr><td><input type = 'radio' name = 'id' value = '49' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '14' readonly></td>
</tr>
<tr><td><input type = 'radio' name = 'id' value = '73' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '15' readonly></td>
</tr>
<tr><td><input type = 'radio' name = 'id' value = '97' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '16' readonly></td>
</tr>
<tr><td colspan = '3' align = 'center'><input type = 'submit' name = 'go' value = 'GO'></td></tr>
</table>
</form>
以下是生成HTML的PHP:
$sql='SELECT `TeamID`, `League`,`Season` FROM teams WHERE `FranchiseID` = 0 GROUP BY `League`,`Season` ORDER BY `League` ASC ,`Season` ASC ';
$unmatched = $db2->get_results($sql);
if ($db2->num_rows>0) {
echo "<form method = 'post' action = 'index.php?choice=matcht&stage=1'>";
echo "<table width = '50%' border = '1'>";
echo "<thead><tr>\n";
echo "<th>Select</th>\n";
echo "<th>League</th>\n";
echo "<th>Season</th>\n";
echo "</tr></thead>\n";
foreach ( $unmatched as $unmatch )
{
// Access data using object syntax
echo "<tr>";
echo "<td><input type = 'radio' name = 'id' value = '$unmatch->TeamID' ></td>\n";
echo "<td><input type = 'text' name = 'league' value = '".$unmatch->League."' readonly></td>\n";
echo "<td><input type = 'text' name = 'season' value = '".$unmatch->Season."' ></td>\n";
echo "</tr>\n";
}
echo "<tr><td colspan = '3' align = 'center'><input type = 'submit' name = 'go' value = 'GO'></td></tr>\n";
echo "</table>\n";
echo "</form>\n";
答案 0 :(得分:3)
所有文本输入都具有相同的名称,最后一个输入覆盖其他输入。使用数组并将索引设置为id
,以便了解要获取的内容:
<tr><td><input type = 'radio' name = 'id' value = '1' ></td>
<td><input type = 'text' name = 'league[1]' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season[1]' value = '12' readonly></td>
然后你可以得到它:
$id = $_POST['id'];
$league = $_POST['league'][$id];
$season = $_POST['season'][$id];