-2

我希望我的程序在我的页面上的下拉菜单中的列表中列出来自 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>

这段代码完美运行,它查找我需要的数据并将其发布在下拉列表中但所有内容都发布在一行中..我希望它在彼此下方列出..请帮助我!

4

1 回答 1

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>

编辑:

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

于 2013-08-13T12:35:56.547 回答