我有以下代码,它包含更多行,每行包含一个选择列表。我需要收集结果并通过提交。 问题是我不知道会有多少行,所以我需要使用for循环。 这样我就不能引用$ _POST ['anything'],因为它在每个循环中都会覆盖它自己。 请帮助。
<?php
print"<table class='pairs'>";
print"<tr>";
print"<td>";
print "<Form name='form5' method='post'>";
$numcols=4;
$sqlheaders=array("foo", "bar", "hallo", "world");
for($q=0;$q<$numcols;$q++)
{
print "<tr>";
print "<td>";
print "sel_".$q;
print "</td>";
print "<td>";
print "no such data";
print "</td>";
print "<td>";
print "<Select name='sel_'.$q????>";
print "<option value='default'>...Choose</option>";
foreach ($sqlheaders as $sqlheader)
{
print "<option value='sqlheader_'".$sqlheader."> $sqlheader</option>";
}
print "</select>";
print "</td>";
print "</tr>";
}
print "<tr>";
print "<td>";
print "<Input type='hidden' name ='numcols' value ='$numcols' >";
print "<input type='submit' name='submit_uploadpairs' value='Mehet'/>";
print "</td>";
print "</tr>";
print "</Form>";
for($i=0;$i<$numcols;$i++)
{
$result=$_POST['sel_'?????];
echo $result;
echo "<br>";
}
&GT;
答案 0 :(得分:2)
给他们起个名字......
print "<Select name='Dropdowns[$q]'>";
然后在你的其他循环...
for($i=0;$i<$numcols;$i++)
{
$result=$_POST['Dropdowns'][$i];
echo $result;
echo "<br>";
}