ユーザーが指定した日付の範囲について、データベースから各日付のレコードを表示したいと考えています。つまり、ユーザーが 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);