[英]mySql fetch array ignore null value
在这里,我使用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
你可以这样尝试
while ($row = mysql_fetch_array($result)) {
if(isset($row['Series'])) {
$series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ." </option>";
}
}
尝试这个...
<select id="Series1" onchange="changeVal('Series1')">
<option value="">Please select</option>
<?php
while ($row = mysql_fetch_array($result))
{
if($row['Series'] != '' || $row['Series'] != NULL)
{
?>
<option value="<?php echo $row['Series']; ?>"><?php echo $row['Series']; ?></option>
</select>
<?php
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.