开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜