Php 如何检测mySQL中的表行是否有文件?
我的SQL数据库中有一个表Php 如何检测mySQL中的表行是否有文件?,php,mysql,Php,Mysql,我的SQL数据库中有一个表friends: ╔════╦═══════╦═══════╦═══════╗ ║ id ║ name1 ║ name2 ║ name3 ║ ╠════╬═══════╬═══════╬═══════╣ ║ 1 ║ fred ║ ║ ║ ║ 2 ║ tom ║ ║ ║ ╚════╩═══════╩═══════╩═══════╝ 现在我想检测name2是否有任何内容 $sql = $pdo->prepar
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";
};
但是现在我有一个问题,我得到了id1
和2
:有内容
,id3
:没有内容
。但是对于name2
来说,实际上应该总是没有内容。我做错了什么 如果列为空(不是null,而是“”),则
将被评估为false
尝试:
if(!$result['name2']){
@Daan:太好了!谢谢
if(!result)
if(!result || result == '')