如何在下拉列表中显示我的输出

时间:2013-08-13 12:30:13

标签: php html

我希望我的程序在我页面的下拉菜单中的列表中列出mysql表中的数据。 这是我的代码:

   <fieldset>
<legend> Selecteer uw Categorie </legend>

<label for   ="Categorie"> Categorie </label>
<select name ="Categorie" id="Categorie">
<datalist id ="Categorie">
<Option Value="Router">Router</option>
<Option Value="Switch">Switch</option>
<Option Value="Toestel">Toestel</option>
<Option Value="Basisstation">Basisstation</option>
<Option Value="Repeaters">Repeaters</option>
<Option Value= <?php
$con=mysqli_connect("localhost","root","admin","inventarisdb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM Categorien");





while($row = mysqli_fetch_array($result))
  {
  echo "<ul>";
  echo "<li>" . $row['Categorieen1'] . "</li>";

  echo "</ul>";
  }
echo "</table>";


mysqli_close($con);
?> 



</option>

</select>
</datalist>

</fieldset>

这些代码运行完美,它查找我需要的数据并将其发布在下拉列表中但是它全部发布在一行中.. 我希望它被列在彼此之下.. 请帮帮我!

1 个答案:

答案 0 :(得分:0)

它们都在一行中,因为您将结果放在一个<option>标记中。

试试这个:

<Option Value="Basisstation">Basisstation</option>
<Option Value="Repeaters">Repeaters</option>
    <?php
        $con=mysqli_connect("localhost","root","admin","inventarisdb");
        // Check connection
        if (mysqli_connect_errno())
        {
            echo "<option>Failed to connect to MySQL: " . mysqli_connect_error()."</option>";
        }

        $result = mysqli_query($con,"SELECT * FROM Categorien");

        while($row = mysqli_fetch_array($result))
        {
             echo "<option>".$row['Categorieen1'] . "</option>";
        }

        mysqli_close($con);
    ?> 

</select>
</datalist>

</fieldset>

编辑:

抱歉我忘记了while循环XP中的第二个echo错误!