创建一个IF语句,如果GROUP_CONCAT不返回任何结果。

时间:2022-09-22 15:50:38

I have a GROUP_CONCAT:

我有一个GROUP_CONCAT:

GROUP_CONCAT(CASE WHEN c.twitter IS NOT NULL AND 
c.twitter <> '' THEN CONCAT('!',c.twitter) END SEPARATOR ' ') AS tweetWinners

This works great when the user has a twitter name in the database. I then store this like so:

当用户在数据库中有一个twitter名称时,这种方法非常有效。然后我这样存储:

 $tweeters = $row['tweetWinners'];

Which gives me a list like:

这给了我一个列表:

@twitteruser1 @twitteruser2 @twitteruser3

However, I want to display two different options:

然而,我想展示两种不同的选择:

if ($tweeters == '') {

echo "Something";    

} else {

echo "$tweeters";    

}

But it always jumps to the else even if there aren't any twitter users.

但即使没有twitter用户,它也总是跳到别的地方。

Any help would be appreciated so that I know

我知道,任何帮助都是值得感激的。

1 个解决方案

#1


2  

GROUP_CONCAT() returns NULL if there are no non-NULL-Values. see http://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_group-concat

如果没有非空值,GROUP_CONCAT()将返回NULL。看到http://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html function_group-concat

NULL is not an empty string. COALESCE might help. http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html#function_coalesce

NULL不是空字符串。合并可能会有所帮助。http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html function_coalesce

#1


2  

GROUP_CONCAT() returns NULL if there are no non-NULL-Values. see http://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_group-concat

如果没有非空值,GROUP_CONCAT()将返回NULL。看到http://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html function_group-concat

NULL is not an empty string. COALESCE might help. http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html#function_coalesce

NULL不是空字符串。合并可能会有所帮助。http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html function_coalesce