在这里,我使用 php 使用数据库字段填充我的下拉列表 我的代码如下,
while ($row = mysql_fetch_array($result)) {
$series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ." </option>";
}
获取后我将它回显到 html
<select id="Series1" onchange="changeVal('Series1')">
<option value="">Please select</option>
<?php echo $series1 ?>
</select>
我的问题是我在数据库字段中有一些空值,我不希望将其插入到选项字段中。我的最终结果现在看起来像这样
请帮助我。
最佳答案
试试这个
while ($row = mysql_fetch_array($result)) {
if($row['Series'] != '' || $row['Series'] != NULL) {
$series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ." </option>";
}
}
或
在你的sql查询中
SELECT * FROM your_table WHERE Series IS NOT NULL
关于php - mySql 获取数组忽略空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16602759/