title: foreach Loop is repeating last item in array
body: <p>I am trying to write a foreach loop that will send a separate report by mail for each array element, but it keeps outputting the last element only.  I've tried writing this so many ways that I think I'm starting to repeat myself.  Please help.</p>
  
  <pre><code>$items = array(1 =&gt; 1, 2 =&gt; 2, 3 =&gt; 3, 7 =&gt; 4, 8 =&gt; 5,9 =&gt; 6, 17 =&gt; 8, 18 =&gt; 338, 19 =&gt; 50, 23 =&gt; 52, 11 =&gt; 7, 16 =&gt; 44,  4 =&gt; 11, 5 =&gt; 22, 6 =&gt; 33);
  
  foreach ($items as $id =&gt; $number) {
  //I am querying a pervasive database here
  $wtdVar = $dbx-&gt;getOne('SELECT SUM(sales) FROM table WHERE date1 &gt;= '.$wkstart3.' AND date2 &lt;= '.$today3.' AND category &lt;&gt; \'ABC\' AND number = '.$number);
  
  if (DB::isError($wtdVar)) {
      echo '&lt;div class="error"&gt;Error: - '.$wtdVar-&gt;getDebugInfo().'&lt;/div&gt;';
  }
  
  //get the goal for the week so far, use date variables with 2 at the end for postgres queries
  $wtdgoal = $db-&gt;getOne("SELECT SUM(goal) FROM table2 WHERE id = $id AND gdate BETWEEN '$wkstart2' AND '$today2'");
  if (DB::isError($wtdgoal)) {
      echo '&lt;div class="error"&gt;Error: - '.$wtdgoal-&gt;getDebugInfo().'&lt;/div&gt;';}
  }
  </code></pre>
  
  <p>There are 15 items in the array, and the e-mail of the report works just fine, but the data in the report is the last item 15x.  There are more data, and with a static variable where I have the array elements it works perfectly, but I need it to loop because I have to use this data at many places.</p>