MySQL计数字段,包含任何数据

时间:2021-10-29 06:26:52

Problem: I have database where is website column which contains 20results. When I try to count the amount of websites it returns me 50.

问题:我的数据库在哪里是网站列,其中包含20个结果。当我尝试计算网站数量时,它会返回50。

Known Issue:I have 50rows on my database and it returns them all, so it also counts empty spaces, how to prevent counting empty spaces ?

已知问题:我的数据库中有50个并且它们全部返回,因此它还会计算空格,如何防止计算空格?

$query = "SELECT COUNT(website) FROM data";
$result = mysqli_query($connection, $query);
if (!$result) {
    die("Database query failed.");      
}
while($row = mysqli_fetch_row($result)){
    var_dump($row);
    echo "<hr />";
}

2 个解决方案

#1


1  

Just check if "website" column is not blank in database

只需检查数据库中“网站”列是否为空白

Try this

$query ="SELECT COUNT(website) FROM data WHERE (website != '' OR website IS NOT NULL)";

#2


0  

Use WHERE condition for check for IS NOT NULL and blank values.

使用WHERE条件检查IS NOT NULL和空值。

$query ="SELECT COUNT(website) FROM data WHERE website != '' or website IS NOT NULL";

#1


1  

Just check if "website" column is not blank in database

只需检查数据库中“网站”列是否为空白

Try this

$query ="SELECT COUNT(website) FROM data WHERE (website != '' OR website IS NOT NULL)";

#2


0  

Use WHERE condition for check for IS NOT NULL and blank values.

使用WHERE条件检查IS NOT NULL和空值。

$query ="SELECT COUNT(website) FROM data WHERE website != '' or website IS NOT NULL";