Dan McCready
Dan McCready

Reputation: 21

Selected Value for MySQL generated Drop Down List

I have a mysql generate dropdown list..need to add in a pre selected option such as "Please Choose Availability". Not too sure how to do this as the drop down content is generated from a database

<?php


$sql = "SELECT DISTINCT availability FROM properties";
$result = mysql_query($sql);

echo "<select name='property'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='". $row['availability']. "'>" . $row['availability'] ."</option>";
}
echo "</select>";

?>

Upvotes: 0

Views: 1576

Answers (2)

slash197
slash197

Reputation: 9034

echo "<select name='property'><option value=''>Please Choose Availability</option>";

Upvotes: 1

Rukmi Patel
Rukmi Patel

Reputation: 2561

if you want static first value for dropdown then you can do it like this.

echo "<select name='property'><option value=''>Please Choose Availability </option>";

while ($row = mysql_fetch_array($result)) {
   echo "<option value='". $row['availability']. "'>" . $row['availability'] ."</option>";
} 
echo "</select>";

Upvotes: 1

Related Questions