开发者

How to exclude records from mysql query count?

开发者 https://www.devze.com 2023-03-14 16:39 出处:网络
How can i count all facebook profiles from facebook column? I used thi开发者_运维知识库s $query = \"SELECT COUNT(facebook) FROM members\";

How to exclude records from mysql query count?

How can i count all facebook profiles from facebook column?

I used thi开发者_运维知识库s

    $query = "SELECT COUNT(facebook) FROM members";  
    $result = mysql_query($query) or die(mysql_error()); 
    foreach(mysql_fetch_array($result) as $fbcount);

And it give result 5.

How can i make it to count just 3?


Your query is simply doing a COUNT on facebook column without using any conditions. And therefore the query will return as many records as you have in the table.

Try this:

SELECT COUNT(1)
FROM `members`
WHERE `facebook` != '' 
AND `facebook` IS NOT NULL;


Change it to

 $query = "Select count(facebook) as Count from members 
 where facebook = 'http://www.facebook.com'"
0

精彩评论

暂无评论...
验证码 换一张
取 消