2013-05-17 70 views
0

我在这里填充我的使用PHP 我的代码如下数据库字段的下拉列表中,MYSQL获取数组忽略空值

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> 

我的问题是我在数据库字段中有一些空值,我不希望将它插入到选项字段中。我的最终结果现在这个样子 preview

请帮助我。

+0

分享你的SQL查询,可以帮助我们确定什么错误... – Borniet

+2

加上'WHERE COL是不是在where子句 –

+0

烨NULL',JW钉它其实甚至都不需要请参阅SQL :-) – Borniet

回答

4

试试这个

while ($row = mysql_fetch_array($result)) { 
    if($row['Series'] != '' || $row['Series'] != NULL) { 
     $series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ."    </option>"; 
    } 
} 

OR

在SQL查询

SELECT * FROM your_table WHERE Series IS NOT NULL 
+0

这对我有用,谢谢 – Hareesh

2

你可以尝试这样的

while ($row = mysql_fetch_array($result)) { 
    if(isset($row['Series'])) { 
    $series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ."    </option>"; 
     } 
     } 
1

尝试......

<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 
    } 
} 
?>