title: Count non-empty fields mysql
body: <p>I want to count how many fields of a specific fieldset are empty in mysql, I've found some examples but they all go through the whole table.</p>
  
  <p>Basically I have 8 fields, </p>
  
  <p>listing_photo_1 to listing_photo_8, I want to get the count of how many of them are filled.</p>
  
  <p>I tried:</p>
  
  <pre><code>$result=mysql_query("SELECT count(*) as total from listings 
                         WHERE listing_photo_1 IS NOT NULL AND 
                               listing_photo_2 IS NOT NULL AND 
                               listing_photo_3 IS NOT NULL AND 
                               listing_photo_4 IS NOT NULL AND 
                               listing_photo_5 IS NOT NULL AND 
                               listing_photo_6 IS NOT NULL AND 
                               listing_photo_7 IS NOT NULL AND 
                               listing_photo_8 IS NOT NULL AND 
                               pmpid = '$pmpid'");
  
  $data=mysql_fetch_assoc($result);
  echo $data['total'];
  </code></pre>
  
  <p>Which results in: <code>1</code></p>
  
  <p>To clarify the result I am expecting:</p>
  
  <p>listing_photo_1: filled </p>
  
  <p>listing_photo_2: filled</p>
  
  <p>listing_photo_3: filled</p>
  
  <p>listing_photo_4: empty</p>
  
  <p>listing_photo_5: empty</p>
  
  <p>listing_photo_6: empty</p>
  
  <p>listing_photo_7: empty</p>
  
  <p>listing_photo_8: empty`</p>
  
  <p>The result should be <code>3</code> </p>