title: Counting specific rows after dynamical WHERE clause query in PDO
body: <p>I'm following <a href="https://phpdelusions.net/pdo_examples/dynamical_where" rel="nofollow noreferrer">this tutorial</a> for a dynamical WHERE clause query in PDO.</p>
  <p>Let's suppose I have a short version of the tutorial code, just like this:</p>
  <pre><code>
  
  // always initialize a variable before use!
  $conditions = [];
  $parameters = [];
  
  // conditional statements
  if (!empty($_GET['name']))
  {
     // here we are using LIKE with wildcard search
     // use it ONLY if really need it
     $conditions[] = 'name LIKE ?';
     $parameters[] = '%'.$_GET['name'].&quot;%&quot;;
  }
  
  if (!empty($_GET['sex']))
  {
     // here we are using equality
     $conditions[] = 'sex = ?';
     $parameters[] = $_GET['sex'];
  }
  
  
  // the main query
  $sql = &quot;SELECT * FROM users&quot;;
  
  // a smart code to add all conditions, if any
  if ($conditions)
  {
     $sql .= &quot; WHERE &quot;.implode(&quot; AND &quot;, $conditions);
  }
  
  // the usual prepare/execute/fetch routine
  $stmt = $pdo-&gt;prepare($sql);
  $stmt-&gt;execute($parameters);
  $data = $stmt-&gt;fetchAll();
  
  </code></pre>
  <p>By adding the line <code>$count = $stmt-&gt;rowCount();</code>, I could count the rows.</p>
  <p>Now let's suppose I have data like this:</p>
  <pre><code>| ID | User name    | sex     |
  | -- | ------------ | --------|
  | 1  | Sandra Smith | female  | 
  | 2  | Ben Smith    | male    | 
  | 3  | John Lee     | male    | 
  | 4  | John Smith   | male    | 
  </code></pre>
  <p>If I searched for &quot;Smith&quot; now, I would get 3 results and when I echo <code>$count</code>, I would get displayed the number 3.</p>
  <p><strong>Question:</strong>
  I also want to echo how many female and male user I get by the exact same query.
  I searched a lot over the internet, but can't find a case using PDO where this is solved. Also, I am not sure if I need another extra query to get the number of female and male user.</p>