【发布时间】:2014-04-22 01:24:18
【问题描述】:
我正在尝试在 PHP 中动态填充下拉列表,这会导致无限循环并且我的浏览器崩溃。我不知道如何正确地让它显示一个表中的所有行,但我认为这将是一个相对简单的修复。 while 循环可能会把它扔掉。如果您需要更多信息,请告诉我,我正在关注此示例,但我的示例是用 PDO 编写的:
Dynamic drop down list using html and php
<h3>Company Listing</h3>
<select name='companies'>
<option value="">--- Select ---</option>
<?php
//gets user's info based off of a username.
$query = "SELECT business_name FROM Businesses";
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
}
//fetching all the rows from the query
$profileRow = $stmt->fetch();
while ($profileRow)
{
?>
<option value="<?php echo $profileRow['business_name']?>"><?php echo $profileRow['business_name']?></option>
<?php
}
?>
</select>
<p></p>
【问题讨论】:
标签: php html mysql pdo while-loop