我有它不同的條目,如開始日期(合同),一些隨機的文件和月結單和收據一張桌子,就像這樣:生成報告與while循環
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
DOCUMENTS
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
我的目標是產生如下所示的輸出。 顯示所有存在的文件,其中CHECK?是的,每月在哪裏顯示丟失的文件?是是的。
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
我寫了一些代碼,但我不明白如何包括每月循環顯示發票和收據。
QUERY
// 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
<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>
我近視。建議的校正與接受的答案的拼寫相匹配。 – Matsmath 2016-05-05 19:26:44