Ho una tabella che genera un report.
C'è una data iniziale (contract), qualche documento casuale e mensilmente delle fatture e delle ricevute:

codice:
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  Recepit        Yes           Yes
DOCUMENTS
codice:
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


Vorrei ottenere il risultato come sotto. Mostrare tutti i documenti dove la condizione é Yes e mostrare anche quelli mancanti fino alla data odierna se l'opzione MONTHLY é Yes

codice:
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  Recepit         01/02/2013 OK
06  Invoice         01/03/2013 OK
07  Recepit         01/03/2013 OK
08  Invoice         01/04/2013 Missing
09  Recepit         01/04/2013 Missing
10  Invoice         01/05/2013 Missing
11  Recepit         01/05/2013 Missing

Ho scritto qualche linea do codice, però non ho capito come inserire il loop per estrarre ed includere i documenti gererati mensilmente come Invoices e Recepit.

QUERY
codice:
// 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'];

WHILE
codice:
<tbody>
<?php
    $i=0;
        while ($i < $num) {
        $document_type_id = mysql_result($result,$i,"document_type_id");
        $document_type = mysql_result($result,$i,"document_type");
    ?>
    <tr class="grade">

    <td><?php echo $document_type_id; ?></td>
    <td><?php echo $document_type; ?></td>
    <td>
    <?php 
        if (in_array($document_type_id, $check)) { 
        echo "<p style='color:green'>Ok</p>";
        } else {
        echo "<p style='color:red'>Miss</p>";   
        }
     ?>
     </td>
     </tr>
     <?php
         $i++;
         }
      ?>                    
</tbody>