当我尝试下面的代码时,我得到一个空白的下拉列表。 这段代码有什么问题吗?
<?php
include ("Connect.php");
$db = new mysqli('localhost', $dbuser, $dbpass, $dbname);
?>
<div class="label">Select Customer Name:</div>
<select name="CustomerName">
<option value = "">---Select---</option>
<?php
$stmt = $db->prepare("SELECT `CustomerName` FROM `tafileuploadmappinghistory`");
$stmt->execute();
$stmt->bind_result($name);
while ($stmt->fetch()){
echo "<option value='$name'></option>";
}
$stmt->close();
?>
</select>
答案 0 :(得分:1)
只需从
更新这一行echo "<option value='$name'></option>";
到
echo "<option value='$name'>$name</option>";
答案 1 :(得分:0)
在while循环中使用此代码来获取数据
while($stmt->fetchAll()) {
}