Reputation: 169
I'm trying to add placeholder for my drop-box which gets results from mySQL and I don't know is there a way or not.
<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>
Upvotes: 3
Views: 1879
Reputation: 2711
Try this :
<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>
Upvotes: 4
Reputation: 3375
If you talk for option inside the results from MySQL you can disable it like that
echo '<option value="'.$row['id'].'" disabled>'.$row['training_type'].'</option>';
If you talk for placeholder in select dropdown along with results from MySQL before your loop simply put another
<select>
<option value="">placeholder</option>
<?php
...
while ( ... ) {
echo '<option value="'.$row['id'].'">'.$row['training_type'].'</option>';
}
?>
</select>
Upvotes: 2
Reputation: 2935
Check this, I've added <option value="">Placeholder</option>
, I think you
can use this as a placeholder.
<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>
Upvotes: 4