我试图为我的投递箱添加占位符,该投放箱可以获取mySQL的结果,而且我不知道是否有办法。
<div class="select_drp">
<?php
$query = mysql_query("SELECT * FROM training_list");
echo '<select class="select_drp" name="insert_training" required>';
while ($row = mysql_fetch_array($query)) {
echo '<option value="'.$row['id'].'">'.$row['training_type'].'</option>';
}
echo '</select>';
echo "<br/><br/>";
?>
</div>
答案 0 :(得分:4)
检查一下,我添加<option value="">Placeholder</option>
,我想你
可以使用它作为占位符。
<div class="select_drp">
<?php
$query = mysql_query("SELECT * FROM training_list");
echo '<select class="select_drp" name="insert_training" required>';
echo '<option value="">Placeholder</option>';
while ($row = mysql_fetch_array($query)) {
echo '<option value="' . $row['id'] . '">' . $row['training_type'] . '</option>';
}
echo '</select>';
echo "<br/><br/>";
?>
</div>
答案 1 :(得分:4)
试试这个:
<div class="select_drp">
<?php
$query = mysql_query("SELECT * FROM training_list");
echo '<select class="select_drp" name="insert_training" required>';
echo '<option value="" disabled selected style="display: none;">Please Choose</option>'; //This line your placeholder
while ($row = mysql_fetch_array($query)) {
echo '<option value="'.$row['id'].'">'.$row['training_type'].'</option>';
}
echo '</select>';
echo "<br/><br/>";
?>
</div>
答案 2 :(得分:2)
如果你在MySQL的结果中谈论选项,你可以像那样禁用它
echo '<option value="'.$row['id'].'" disabled>'.$row['training_type'].'</option>';
如果你在选择下拉列表中的占位符以及来自MySQL的结果在循环之前简单地说出另一个
<select>
<option value="">placeholder</option>
<?php
...
while ( ... ) {
echo '<option value="'.$row['id'].'">'.$row['training_type'].'</option>';
}
?>
</select>