title: Two PDO errors when executing rowCount and second foreach loop
body: <p>Been struggling at this for a couple of hours now. Can anybody point out where I'm going wrong. </p>
  
  <p>The <strong>first error</strong> I get is:    </p>
  
  <pre><code>Fatal error: Call to undefined method PDO::rowCount() in
  pm_wall.php on line 8
  Call Stack: 0.0000 643680 1. {main}()
  index.php:0 0.0015 662904 2.
  include('pm_wall.php')
  index.php:117
  </code></pre>
  
  <p>The <strong>second error</strong> I get is:</p>
  
  <pre><code>Warning: Invalid argument supplied for foreach() in pm_wall.php on line 19
  
  Call Stack:
      0.0000     643296   1. {main}() index.php:0
      0.0015     649864   2. include(index.php:117
  </code></pre>
  
  <p>How do I go about resolving this? Here is my code below:</p>
  
  <pre><code>$sql = "SELECT * from pm_msg";
  $result = $pdo-&gt;query($sql);
  if($pdo-&gt;rowCount() &gt; 0 &amp;&amp; !empty($result)) // first error occurs here
  {
      foreach ($result as $row) 
      {
          $user_id = $row['user_id'];
          echo '&lt;div id="content"&gt;
                      &lt;div class="stbody"&gt;
                      &lt;div class="stimg"&gt;';
  
          // set profile picture  
  
          $sql = "SELECT img FROM pm_user WHERE id=$user_id";
          $result = $pdo-&gt;query($sql);
          foreach ($result as $row) // second error occurs here
          {
              echo $row['img'];
          }
  
          echo '&lt;div id="stexpandbox"&gt;&lt;div&gt;&lt;/div&gt;';       
          echo '&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;';
      }
  }
  else
      {
          echo 'Wanna be starting soemthing?';
      }
  </code></pre>