Paavo Doe Paavo Doe - 1 year ago 100
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 />";

Answer Source

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)";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download