从多个字段下拉菜单

时间:2014-07-17 07:45:53

标签: php mysql drop-down-menu

这是我之前提出的问题的补充。在雕刻机的下拉框中,我希望这个盒子可以收集三个字段的姓氏,Engraver1Surname,Engraver2Surname和Engraver3Surname。我还希望每个名称只出现一次并按字母顺序排列。我的代码不起作用,这意味着我再次弄错了。这个东西真的很有挑战性,我很喜欢它,但我不想成为连续害虫。这就是我尝试过的。

$sql = "SELECT DISTINCT Engraver1Surname, Engraver2Surname, Engraver3Surname FROM engravers Where Engraver1Surname, Engraver2Surname, Engraver3Surname <> '' AND  Engraver1Surname, Engraver2Surname, Engraver3Surname IS NOT NULL ORDER by Engraver1Surname, Engraver2Surname, Engraver3Surname";
    $result = mysql_query($sql);

    echo "<select name\\='Engraver1Surname'>";
      echo "<option value='$_POST'>Engraver</option>";
      while ($row = mysql_fetch_array($result)) {
      echo "<option value='" . $row['Engraver1Surname'] . "'>" .$row['Engraver1Surname'] . "</option>";
      }
      echo "</select>";

1 个答案:

答案 0 :(得分:0)

$name=array('Engraver1Surname','Engraver2Surname','Engraver3Surname');

$option=array();

while ($row = mysql_fetch_array($result)) {

      for($x=0;$x<3;$x++){
      $option.=$row[$name[$x]];
      }

}

asort($option);

for($y=0;$y<sizeof($option);$y++){
echo "<option value='" . $option[$y]. "'>" .$option[$y] . "</option>";
}

echo "</select>";

希望它能解决你的问题