PHP循环意外停止

I have a table (table3) in MYSQL with 99 text fields (field1, filed2, ...,field99). I wanted to count the non-empty values of each field so I wrote a simple php script with a for loop as below:

for($i = 1; $i <= 99; $i++)
{
  $sqlstm = "SELECT COUNT(field$i) FROM table3 WHERE field$i IS NOT NULL AND field$i <> '';";
  $r = @mysqli_query($dbc, $sqlstm);
  if($r)
  {
    while($row = @mysqli_fetch_array($r)) 
    {   
        echo "<p>$row[0]</p>
"; 
    }
  }
  else
  {
    echo "field $i error: " . mysqli_error($dbc);
  }
}

But the loop stopped after showing four values (field1 to filed4) and no error message. I do have all 99 fields with data in table3 and I could run the query manually for any field. Could this due to browser timeout? Can someone help me? Thanks.

 $sqlstm = "SELECT COUNT(field$i) FROM table3

you are selecting the columns here, your table has 99 rows but apperantly only 4 columns

what you could better do is

$sqlstm = "SELECT * FROM table3 WHERE (column name) IS NOT NULL";
$count = 0
for($sqlstm as $one) {
    $count = $count + 1;
}
echo($count);

or something along those lines