PHP PDO检查返回值是否为null

PHP PDO检查返回值是否为null,php,mysql,pdo,Php,Mysql,Pdo,我正在为PDO问题挣扎。我想检查返回的列中是否有任何值 我正在这样做: function populateAltsDropdown($list) { echo "<div class='dropdown'> <button class='btn btn-secondary btn-sm dropdown-toggle' type='button' id='dropdownMenuButton' data-toggle='dropdown' aria-haspop

我正在为PDO问题挣扎。我想检查返回的列中是否有任何值

我正在这样做:

function populateAltsDropdown($list)
{
    echo "<div class='dropdown'>
    <button class='btn btn-secondary btn-sm dropdown-toggle' type='button' id='dropdownMenuButton' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>
    Alts
    </button>
    <div class='dropdown-menu' aria-labelledby='dropdownMenuButton'>";

    foreach ($list as $row)
    {
        if($row['name'] != null) {
            echo "<a class='dropdown-item disabled' href='#'>" . $row['name'] . "</a>";
        }
        else
        {
            echo "No Alts";
        }

    }
    echo "</div></div>";
}
我可以在列表中列出如下值:

 ID--------Name
"1002303","Name 1"
"2132444","Name 2"
"4324323",null
"4343433",null

我需要一些帮助来过滤那些没有名字的值,那些带有null的值。

尝试使用
is\u null
==
操作符。比如

if(!is_null($row['name']))


更改sql查询以排除空值或空值?如果您不关心
null
值,请使用
内部联接
代替标题,因为alt_id在其他地方使用,但是并非所有值都有名称,我需要显示有名称的值,而不显示没有名称的值。请尝试
$row['name'!==空
if(!is_null($row['name']))
if($row['name'] !== NULL))