我正在尝试通过嵌入在 HTML 中的 PHP 填充下拉列表。
这是我到目前为止所拥有的:
<select name="ChapterList" id="ChapterList" style="width:120px;">
<?php
$username = "xxxxxxxxxxx";
$password = "xxxxxxxxx";
$database = "xxxxxxxxxxxxxx";
$host = "xxxxxxxx.mydomainwebhost.com";
@mysql_connect($host, $username, $password) or die("Unable to connect to database");
@mysql_select_db($database) or die("Unable to select database");
$query = "SELECT * FROM Chapters ORDER BY Id";
$ListOptions = mysql_query($query);
while($row = mysql_fetch_array($ListOptions))
{
echo "<option value='".$row['Id']."'>".$row['ChapterName']."</option>"
}
?>
</select>
我知道我收到了预期的结果,因为如果 I echo $row['ChapterName'];
,我在数据库中的当前值以正确的顺序列出,那么为什么当我echo "<option value='".$row['Id']."'>".$row['ChapterName']."</option>"
的列表什么也没收到时呢?