title: Generating report with while loop
body: <p>I have a table with various entries such as start date (contract), some random documents and monthly invoices and receipt in it, like this:</p>
  
  <pre><code>DOCUMENT TYPES
  ID TYPE        CHECK?     MONTHLY?
  1  Contract    Yes        No
  2  Documents   No         No
  3  Policy      Yes        No
  4  Order       No         No
  5  Invoice     Yes        Yes
  6  Receipt     Yes        Yes
  </code></pre>
  
  <p>DOCUMENTS</p>
  
  <pre><code>ID TYPE DATE
  1  1    01/01/2013
  2  2    01/01/2013
  3  3    01/01/2013
  4  5    01/02/2013
  5  6    01/02/2013
  6  4    14/02/2013
  7  5    01/03/2013
  8  6    01/03/2013
  
  
  TODAY 05/05/2013
  </code></pre>
  
  <p>My goal is to produce the output as shown below.
  Display all existent documents, where CHECK? is Yes, and display missing documents where MONTHLY? is Yes.</p>
  
  <pre><code>01  Contract    01/01/2013 OK
  02  Documents   01/01/2013 OK
  03  Policy          01/01/2013 OK
  04  Invoice         01/02/2013 OK
  05  Receipt         01/02/2013 OK
  06  Invoice         01/03/2013 OK
  07  Receipt         01/03/2013 OK
  08  Invoice         01/04/2013 Missing
  09  Receipt         01/04/2013 Missing
  10  Invoice         01/05/2013 Missing
  11  Receipt         01/05/2013 Missing
  </code></pre>
  
  <p>I have written some code, but I not understand how to include monthly loop to display invoices and receipts.</p>
  
  <p>QUERY</p>
  
  <pre><code>// Get type
  $query = "SELECT * FROM doc_type
            WHERE check='1'";
  $result = mysql_query($query) or die(mysql_error());
  $num = mysql_numrows($result);  
  
  // Get docs
  $check = array();
  $query2 = mysql_query("SELECT document_type_id FROM documents");
  while ($row = mysql_fetch_assoc($query2)) {
  $check[] = $row['document_type_id'];
  </code></pre>
  
  <p>WHILE</p>
  
  <pre><code>&lt;tbody&gt;
  &lt;?php
      $i=0;
          while ($i &lt; $num) {
          $document_type_id = mysql_result($result,$i,"document_type_id");
          $document_type = mysql_result($result,$i,"document_type");
      ?&gt;
      &lt;tr class="grade"&gt;
  
      &lt;td&gt;&lt;?php echo $document_type_id; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $document_type; ?&gt;&lt;/td&gt;
      &lt;td&gt;
      &lt;?php 
          if (in_array($document_type_id, $check)) { 
          echo "&lt;p style='color:green'&gt;Ok&lt;/p&gt;";
          } else {
          echo "&lt;p style='color:red'&gt;Miss&lt;/p&gt;";   
          }
       ?&gt;
       &lt;/td&gt;
       &lt;/tr&gt;
       &lt;?php
           $i++;
           }
        ?&gt;                    
  &lt;/tbody&gt;
  </code></pre>