title: Foreach nested in a while loop with PDO query
body: <p>To trim the fat so-to-speak in my script I decided to use 1 PDO prepare to span an array of predefined tables. The PDO executes in a <code>while</code> loop and within the <code>while</code> loop there is a <code>foreach</code> to build the output of each result set.</p>
  
  <p>This is code for a search. The script currently searches 3 tables for results (through the <code>while</code> iterations). We will call them tables a, b, and c. For the tested search it finds 2 results in table a, 0 in table b, and 1 in table c. </p>
  
  <p>Though it finds a total of 3 results it only displays 2. One from table 'a' and one from table 'c'. The script is not building the result from the second find in the table 'a'. </p>
  
  <p>I have looked it over until my eyes bleed and searched for maybe something I have wrong, I cant figure it out. Any ideas of what is wrong with this code?</p>
  
  <pre><code>// --- Build an array of places to search
  $tableArray = array("services", "webPages", "dsiu");
  $tableCount = count($tableArray);
  $count = "0";
  $resCount = "0";
  
  $result = "";
  while ($tableCount &gt; $count) {
      // -- Search tables in the array for matches
      $quotedString = $db-&gt;quote($searchString);
      $qSQL = "SELECT title, ldesc, SUM(MATCH(title, sdesc, ldesc) AGAINST(:string IN BOOLEAN MODE)) AS score FROM ".$tableArray[$count]." WHERE MATCH (title, sdesc, ldesc) AGAINST (:string IN BOOLEAN MODE) ORDER BY score DESC";
      $q = $db-&gt;prepare($qSQL);
      $q-&gt;execute(array(':string'=&gt;$quotedString));
  
      // -- keep a count of the results
      $rowCount = $q-&gt;rowCount();
  
      if ($rowCount &gt; 0) {
          $resCount = $resCount + $rowCount;
  
          // -- build result html
          $html = $q-&gt;fetchAll(PDO::FETCH_ASSOC);
          foreach ($html as $row) {
  
              // --- Clean the results for display
              $desc = cleanURL($row['ldesc']);
              $desc = str_ireplace($searchString, '&lt;b&gt;&lt;font color="green"&gt;'.$searchString.'&lt;/font&gt;&lt;/b&gt;', $desc);
              $desc = substr($desc, 0, 300)."...";
  
              $result .= "&lt;font color='red'&gt;&lt;b&gt;".$row['title']."&lt;/b&gt;&lt;/font&gt;&lt;br&gt;".$desc."&lt;br&gt;&lt;br&gt;";
  
          }
      }
  
      $count++;
  }
  </code></pre>