title: PDO equivalent of mysql_fetch_array
body: <p>I am struggling with the PDO equivalent of the following query which calculated how many new items there are in the queue and works out how many weeks to complete them, thereby giving me a workstack timescale:-</p>
  
  <pre><code>//count new to be made
  $new = "SELECT FLOOR(SUM(TotalNew) / 7) AS Weeks FROM 
  (
  SELECT YEAR( date_ready ) , MONTHNAME( date_ready ) , 
  STATUS , COUNT( 
  STATUS ) AS TotalNew
  FROM new
  WHERE 
  (STATUS =  'new'
  OR STATUS =  'progress') 
  GROUP BY YEAR( date_ready ) , MONTHNAME( date_ready ) , 
  STATUS ORDER BY YEAR( date_ready ) , MONTH( date_ready ) 
  ) Total";
  $count = mysql_query($new) or die(mysql_error());
  
  while($row = mysql_fetch_array($count)) {
  $weeks = $row['Weeks'];
  }
  </code></pre>
  
  <p>Where I'm up to is this....</p>
  
  <pre><code>//count new to be made 
  $new = "SELECT FLOOR(SUM(TotalNew) / 7) AS Weeks FROM 
  (
  SELECT YEAR( date_ready ) , MONTHNAME( date_ready ) , 
  STATUS , COUNT( 
  STATUS ) AS TotalNew
  FROM new
  WHERE 
  (STATUS =  'new'
  OR STATUS =  'progress') 
  GROUP BY YEAR( date_ready ) , MONTHNAME( date_ready ) , 
  STATUS ORDER BY YEAR( date_ready ) , MONTH( date_ready ) 
  ) Total";
  
  
  //get count data fromdb
  $stmt = $dbLink-&gt;prepare($new);
  $stmt-&gt;execute();
  </code></pre>
  
  <p>If I add
      $count = $stmt->fetchAll();</p>
  
  <p>and dump the variable, I get 
  array(1) { [0]=> array(2) { ["Weeks"]=> string(2) "16" [0]=> string(2) "16" } } </p>
  
  <p>If I replace  </p>
  
  <pre><code>$count = $stmt-&gt;fetchAll();
  </code></pre>
  
  <p>with</p>
  
  <pre><code>while ($row = $stmt-&gt;fetchAll())  {
  echo "about to print";
  echo "&lt;br&gt;";
  print_r($row);
  echo "&lt;br&gt;";
  echo $row['Weeks'];
  echo "&lt;br&gt;";
  echo "printed";
  }
  </code></pre>
  
  <p>I get a different variation of the array - Array ( [0] => Array ( [Weeks] => 16 [0] => 16 ) ), but not the output I want which is the number relating to Weeks from the query. I've tried error checking with the various echo / print_r to try and see where the outputs match expected output.</p>
  
  <p>The query works fine, and the original mysql_query version also works, so I'm obviously misunderstanding how PDO handles arrays and how to pull an item out from within the array.</p>
  
  <p>I've looked at 
  <a href="https://stackoverflow.com/questions/10911757/how-to-use-pdo-to-fetch-results-array-in-php">How to use PDO to fetch results array in PHP?</a>
  and
  <a href="https://stackoverflow.com/questions/19488364/how-to-properly-use-while-loop-in-pdo-fetchall">how to properly use while loop in PDO fetchAll</a>
  and tried various combinations to no avail. To be honest, even if something randomly worked, I'd prefer to know why and am beginning to question my understanding of arrays.</p>
  
  <p>As always, I'd be grateful for a pointer or two please?</p>
  
  <p>Many thanks,
  Jason</p>