title: PHP Mysql total rows with FOUND_ROWS() and WHERE condition
body: <p>I'm getting x amount of rows from the db which are totalled with the 'totalRows'. From the rows I'd also like to total just those where the result column is equal to 'win'. I'm not seeing an answer either with the echo of 'totalWins'.</p>
  
  <p>Any ideas what I'm doing wrong?</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>public static function getList( $numRows=10000, $order="id DESC" ) {
  $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM table
          ORDER BY " . mysql_escape_string($order) . " LIMIT :numRows";
  
  $st = $conn-&gt;prepare( $sql );
  $st-&gt;bindValue( ":numRows", $numRows, PDO::PARAM_INT );
  $st-&gt;execute();
  $list = array();
  
  while ( $row = $st-&gt;fetch() ) {
    $article = new Article( $row );
    $list[] = $article;
  }
  
  // Now get the total number of rows that matched the criteria
  $sql = "SELECT FOUND_ROWS() AS totalRows";
  $totalRows = $conn-&gt;query( $sql )-&gt;fetch();
  $conn = null;
  return ( array ( "results" =&gt; $list, "totalRows" =&gt; $totalRows[0] ) );
  
  // Now get the total number of rows WITH CONDITION matched
  $sql = "SELECT FOUND_ROWS() AS totalWins WHERE result = 'win'";
  $totalWins = $conn-&gt;query( $sql )-&gt;fetch();
  $conn = null;
  return ( array ( "results" =&gt; $list, "totalWins" =&gt; $totalWins[0] ) );
  </code></pre>