0

我有以下代码,它包含更多行,每行都有一个选择列表。我需要收集结果并通过提交。问题是我不知道会有多少行,所以我需要使用 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>";
}

?>

4

1 回答 1

2

给他们取个名字就行了......

 print "<Select name='Dropdowns[$q]'>";

然后在你的另一个循环中......

for($i=0;$i<$numcols;$i++)
  {   
  $result=$_POST['Dropdowns'][$i];
  echo $result;
  echo "<br>";
 }
于 2013-08-30T10:21:24.760 回答