title: PHP SQL how the get the exact count from a table
body: <p>I have two tables with the following columns:</p>
  
  <ul>
  <li>FAMILY - id, ...</li>
  <li>PRODUCTS - id, idfamily, type, ...</li>
  </ul>
  
  <p><code>FAMILY</code> &amp; <code>PRODUCTS</code> are connected with <code>family.id = products.idfamily</code>.</p>
  
  <p>I'm doing pagination over families with filters based on products types, so I'm trying to get the exact count of <code>FAMILY</code> containing almost one product with a specific type. </p>
  
  <p>First query is ok, I get all the families:</p>
  
  <pre><code>if (!isset($_GET['type']) || $_GET['type'] == 'all') {
      $query_family=mysql_query("SELECT * FROM family");  
  }
  $count=mysql_num_rows($query_family);
  // result = 166
  </code></pre>
  
  <p>Unfortunately, the following query is wrong:</p>
  
  <pre><code>} else {
      $query_family=mysql_query("
        SELECT * FROM family f LEFT JOIN products p ON f.id = p.idfamily  
        WHERE p.type = '$_GET[type]' 
      ");  
  }
  $count=mysql_num_rows($query_family);
  // result = 500+
  </code></pre>
  
  <p>it's wrong because I get <em>all</em> the products with a type, but <strong>I'm trying to get the number of families containing products with the selected type</strong> (<code>$_GET[type]</code>).</p>
  
  <p>Thank you</p>