Paavo Doe Paavo Doe - 1 month ago 5x
MySQL Question

MySQL Count fields which contains any data

Problem: I have database where is website column which contains 20results.
When I try to count the amount of websites it returns me 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 ?

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


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)";