title: Loop through dates and add data to it
body: <p>I want to list all the dates between 2 dates and in that loop, I want to insert data from my database.</p>
  
  <p>As it is right now, the loop lists the same dates and times but with different strings.</p>
  
  <pre><code>2018-02-20 23:55   Took 2 pills
  2018-02-20 23:55   Refilled with 50 pills
  2018-02-20 23:55   Took 2 pills
  2018-02-20 23:55   Took 2 pills
  2018-02-20 23:55   Took 2 pills
  2018-02-20 23:55   Refilled with 40 pills
  </code></pre>
  
  <p>If I remove the while loop, it looks like this:</p>
  
  <pre><code>2018-02-05 18:03   Took 2 pills
  2018-02-03 12:37   Refilled with 50 pills
  2018-02-02 15:00   Took 2 pills
  2018-02-01 13:45   Took 2 pills
  2018-01-31 16:34   Took 2 pills
  2018-01-31 11:02   Refilled with 40 pills
  </code></pre>
  
  <p>I want it to list like this:</p>
  
  <pre><code>2018-02-05 18:03   Took 2 pills
  2018-02-04   Took 0 pills
  2018-02-03 12:37   Refilled with 50 pills
  2018-02-02 15:00   Took 2 pills
  2018-02-01 13:45   Took 2 pills
  2018-01-31   Took 2 pills at 16:34 and refilled with 40 pills at 11:02
  </code></pre>
  
  <p>Here's how the loops looks like:</p>
  
  <pre><code># LOOP
  foreach($get_activity AS $activity) {
  
      # LOOP
      while($date_start != $date_end) {
  
          # VARIABLE
          $date_start += 86400;
  
  
          # ITEMS
          echo '&lt;div&gt;';
  
              # DATE &amp; TIME
              echo '&lt;div class="datetime"&gt;';
                  echo datetime($activity['datetime_occured']);
                  # echo date('Y-m-d', $date_start);
              echo '&lt;/div&gt;';
  
  
              # ACTIVITY
              echo '&lt;div class="string"&gt;';
  
                  # IF
                  if($activity['data_pills_taken'] != 0) {
                      echo 'Tog &lt;span&gt;'.$activity['data_pills_taken'].'&lt;/span&gt; tablett'.($activity['data_pills_taken'] == 1 ? '' : 'er');
  
                  # IF
                  } elseif($activity['data_pills_total'] != 0) {
                      echo 'Fyllde på med &lt;span&gt;'.$activity['data_pills_total'].'&lt;/span&gt; tablett'.($activity['data_pills_total'] == 1 ? '' : 'er');
                  }
  
              echo '&lt;/div&gt;';
  
          echo '&lt;/div&gt;';
  
      }
  
  }
  </code></pre>
  
  <p>Complete source code: <a href="https://gist.github.com/edgren/585d8d1d67c93979003022d8c3cbf5f2" rel="nofollow noreferrer">https://gist.github.com/edgren/585d8d1d67c93979003022d8c3cbf5f2</a></p>
  
  <p>How can I accomplish this?</p>