title: PHP/MySQLi while within while repeats first while values
body: <p>Code:</p>
  
  <pre><code>$query = $db-&gt;query("SELECT day FROM impressions WHERE pub_id = '$pub_id' AND pub_tag = '$pub_tag' AND month = '$month' AND valid = '1' GROUP BY day ASC");
  $stat_rev = $query-&gt;num_rows;
  if($stat_rev &gt; 0) {
      while($revenue = $query-&gt;fetch_array())
      {
          $revenues[] = $revenue;
      }
      foreach($revenues as $revenue)
      {
          echo $rev_day = $revenue['day'].':';
  
          $queryi = $db-&gt;query("SELECT revenue FROM impressions WHERE pub_id = '$pub_id' AND pub_tag = '$pub_tag' AND month = '$month' AND day = '$rev_day' AND valid = '1'");
          while($rev = $queryi-&gt;fetch_array())
          {
              $revs[] = $rev;
          }
          foreach($revs as $rev)
          {
              //$total_rev = $total_rev + $rev['revenue'];
              echo $rev['revenue'].',';
          }
          $queryi-&gt;close();
  
          echo ' - ';
  
          //echo '[\''.$revenue['day'].'\', '.$total_rev.'],';
          $total_rev = 0;
  
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>28:0.001,0.001,0.006, - 29:0.001,0.001,0.006,0.006,0.001, -
  </code></pre>
  
  <p>Database:</p>
  
  <pre><code>28: 0.001
  28: 0.001
  28: 0.006
  29: 0.006
  29: 0.001
  </code></pre>
  
  <p>During the first loop run at which day is 28 the loop show 0.001, 0.001, 0.006.
  Now at second loop run at which day is 29 the loop show 0.001, 0.001, 0.006, 0.006, 0.001.
  The second loop is showing first loop values I have tried but cant fix it I want to show  the values like 28: 0.001, 0.001, 0.006 and 29: 0.006, 0.001.
  Thanks.</p>