title: Print matching result
body: <p>I am trying to make matching of headers and print result. </p>
  
  <p>My goal is to print green color for each user on specific day in a month if the user has record for that day in a db, if not print red. </p>
  
  <p>In table header I print date for specific month.</p>
  
  <pre><code>&lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;/th&gt;
          &lt;th&gt;
              &lt;?php 
                  $date = '2016-11-01';
                  $end = '2016-11-' . date('t', strtotime($date)); //get end date of month
                  while(strtotime($date) &lt;= strtotime($end)) {
                      $day_num = date('d', strtotime($date));
                      $day_name = date('l', strtotime($date));
                      $day_month = date('m', strtotime($date));
  
                      $months[]=$day_name = date('Y-m-d', strtotime($date));
                      $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
                      echo "&lt;td&gt;$day_name &lt;br/&gt; $day_num | $day_month&lt;/td&gt;";
                   }
                ?&gt;
           &lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  </code></pre>
  
  <p>I got this part right. Then I print all users from database by using while loop.</p>
  
  <pre><code>$users = "SELECT UposlenikID, UposlenikIme  FROM uposlenici WHERE Status = 0";
  
      $q = $conn-&gt;query($users);
      $zapisi ="SELECT UposlenikID, date(VrijemeZapisa) as datum FROM users_checked";
  
      $qq = $conn -&gt; query($zapisi);
  
  &lt;tbody&gt;
      &lt;?php 
          $i=1; 
          while ($r=$q-&gt;fetch()) {    
      ?&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;?php  echo $i++;  ?&gt;
          &lt;/td&gt;
          &lt;td&gt;
             &lt;?=$r['UposlenikIme']; ?&gt;                  
          &lt;/td&gt;
          &lt;?php
          foreach ($months as $mjesec) { 
  
                $sql = "SELECT Id, UposlenikID FROM user_checked WHERE TimeStamp = $mjesec ";                     
  
                 $query = $conn -&gt; query($sql);
          &lt;td&gt;
              // here I need to print matching I was using for each loop
             &lt;?php } ?&gt;
          &lt;/td&gt;
  
      &lt;/tr&gt;
      &lt;?php }  // end while loop  ?&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>I was wondering how to match now and if is possible doing things this way. </p>
  
  <p>In db table user_checked I have inserted all users. </p>
  
  <p>Table structure Uposlenici</p>
  
  <pre><code>UposlenikID      UPOSLENIKIME        STATUS
  
  1                  UserName             0 
  2                  UserName2            0
  </code></pre>
  
  <p>Table structure user_checked</p>
  
  <pre><code>Id        UposlenikID        TimeStamp             Command       
  
  1           3           2016-11-27 13:22:14        CheckIN
  2           4           2016-11-28 13:22:17        CheckIN
  3           5           2016-11-29 13:22:20        CheckIN
  4           6           2016-11-30 13:22:24        CheckIN
  </code></pre>
  
  <p>At the end I should get table like this:</p>
  
  <p><a href="https://i.stack.imgur.com/LA49G.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LA49G.jpg" alt="enter image description here"></a></p>