我想在用户提供的日期范围内显示数据库中每个日期的记录。即,如果用户指定 2012-july-2 到 2012-july-4。那么输出必须是
date:2012-july-02
name | intime | outtime |Teamtype
date:2012-july-03
name | intime | outtime |Teamtype
so on..
用于此的 SQL:
$s="SELECT InDate,mstEmp.cardnofrom mstEmp left join dailyattendance ON (InDate BETWEEN '$from' AND '$to' ) AND(dailyattendance.HolderName = mstEmp.empname ) where teamtype='$chk'";
$objDB->SetQuery($s);
$r = $objDB->GetQueryReference();
$sql= SELECT mstEmp.empname,
mstEmp.cardno,
InDate,
dailyattendance.InTime,
dailyattendance.OutTime,
mstEmp.teamtype
FROM mstEmp
LEFT JOIN dailyattendance
ON (InDate BETWEEN '$from' AND '$to') AND (dailyattendance.HolderName =mstEmp.empname )
WHERE mstEmp.teamtype = '$chk'
ORDER BY InDate DESC
$res = $objDB->GetQueryReference();
我尝试的是
<!-- language: lang-php -->
while($rw=mysql_fetch_array($r) )
{
while($row=mysql_fetch_array($res))
{
list($name, $crd,$indate,$in,$out,$t) = $row;
if($rw[1]!=$crd && $row[2]=='')
{
$d1='NULL';
$d2='NULL';
}
else
{
$d1 = date("g:i A", $in);
$d2 = date("g:i A" ,$out);
$d3 = date("d-m-Y (D)", $in);
$bg = '';
if(date('D', $in) == 'Sun' || date('D', $in) == 'Sat')
$bg = 'bgcolor=#EEEEEE';
else
$bg = 'bgcolor= #ECE5B6';
if ($ddate != $row[2])
{
echo "<tr $bg><td colspan=4>Date: ".$d3."</td></tr>";
$ddate = $row[2];
}
}
echo "<tr>";
echo "<td align=left width='35%'>".trim($name)."</td>";
echo "<td align=center width='20%' >".$d1."</td>";
echo "<td align=center width='23%' >".$d2."</td>";
echo "<td align=center width='16%'>".$t."</td>";
echo "</tr>";
}
echo "</table><br>";
echo "</form>";
}
mysql_free_result($res);
mysql_free_result($r);