Php 如何检测mySQL中的表行是否有文件?

Php 如何检测mySQL中的表行是否有文件?,php,mysql,Php,Mysql,我的SQL数据库中有一个表friends: ╔════╦═══════╦═══════╦═══════╗ ║ id ║ name1 ║ name2 ║ name3 ║ ╠════╬═══════╬═══════╬═══════╣ ║ 1 ║ fred ║ ║ ║ ║ 2 ║ tom ║ ║ ║ ╚════╩═══════╩═══════╩═══════╝ 现在我想检测name2是否有任何内容 $sql = $pdo->prepar

我的SQL数据库中有一个表
friends

╔════╦═══════╦═══════╦═══════╗
║ id ║ name1 ║ name2 ║ name3 ║
╠════╬═══════╬═══════╬═══════╣
║ 1  ║ fred  ║       ║       ║
║ 2  ║ tom   ║       ║       ║
╚════╩═══════╩═══════╩═══════╝
现在我想检测
name2
是否有任何内容

$sql = $pdo->prepare("SELECT name2 FROM friends WHERE id = '$id'");
                            $sql->execute();
                            $result = $sql->fetch(PDO::FETCH_ASSOC);
                            if (!$result) {
                            echo "there is no content";
                            } else {
                            echo "there is content";
                            };
但是现在我有一个问题,我得到了id
1
2
有内容
,id
3
没有内容
。但是对于
name2
来说,实际上应该总是
没有内容。我做错了什么

如果列为空(不是null,而是“”),则

将被评估为false

尝试:


if(!$result['name2']){
@Daan:太好了!谢谢
if(!result) 
if(!result || result == '')