我需要检查是否存在每月合同以及是否已签署。我会改进代码,因为它看起来太重了
是时候切换到 PDO,也许我可以重写一些东西来加速脚本
基本上我有一个有 2 列的表,第一列有日期参考,2013/jan,2013/fev ... 和第二列显示检查文档是否存在并有签名。
这是我的代码。有没有办法改进?
// QUERY DB
// Get contract
$contract = array();
$query1 = mysql_query("SELECT * FROM contracts
WHERE ic_id='28'");
while ($row = mysql_fetch_assoc($query1)) {
$contract[] = $row['month'];
}
$signature = array();
$query1 = mysql_query("SELECT * FROM contracts
WHERE ic_id='28'");
while ($row = mysql_fetch_assoc($query1)) {
$signature[] = $row['sign'];
}
// Get START AND END DATE
$startYear = '2012';
$startMonth = '12';
$endYear = '2013';
$endMonth = '12';
$startDate = strtotime("$startYear/$startMonth/01");
$endDate = strtotime("$endYear/$endMonth/01");
$currentDate = $endDate;
结果表
<tbody>
<?php
while ($currentDate >= $startDate) {
$foo = date('Y-m',$currentDate);
$currentDate = strtotime( date('Y/m/01/',$currentDate).' -1 month');
?>
<tr class="grade">
<td>
<?php echo $foo; ?>
</td>
<td>
<?php
if (in_array($foo, $contract)) {
echo "<img src='images/ok.png';
} else {
echo "<img src='images/ko.png'/>";
}
if (in_array($foo, $signature)) {
echo "<img src='imagens/ok.png'/>";
} else {
echo "<img src='imagens/sign.png'/>";
}
?>
</td>
</tr>
<?php
$i++;
}
?>
</tbody>