开发者

Need help to make the first <select> option blank in php retrieving column in mySQL?

开发者 https://www.devze.com 2023-04-08 17:00 出处:网络
I have a good php script that works.But I need to modify it so the first select option is blank.Can anyone开发者_运维百科 help?

I have a good php script that works. But I need to modify it so the first select option is blank. Can anyone开发者_运维百科 help?

<?php
// connect to MySQL
$query = "SELECT <col> FROM <table>";
$result = mysql_query($query);
?>
<select name="sel" id="sel">
<?php
while($row = mysql_fetch_assoc($result)){
echo "<option>{$row['<col>']}</option>";
}
?>
</select>


Is this what you mean?

<?php
// connect to MySQL
$query = "SELECT <col> FROM <table>";
$result = mysql_query($query);
?>
<select name="sel" id="sel">
  <option value="-1"></option>
<?php
while($row = mysql_fetch_assoc($result)){
  echo "<option>{$row['<col>']}</option>";
}
?>
</select>


Just make it blank:

<?php
// connect to MySQL
$query = "SELECT <col> FROM <table>";
$result = mysql_query($query);
?>
<select name="sel" id="sel">
<option></option>
<?php
while($row = mysql_fetch_assoc($result)){
echo "<option>{$row['<col>']}</option>";
}
?>
</select>
0

精彩评论

暂无评论...
验证码 换一张
取 消