$time = $_POST['time'];
$time2 = $_POST['time2'];
$person = $_POST['person'];
if(isset($_POST[search1])){
$strSQL = "SELECT acc_monitor_log.pin,DATE(acc_monitor_log.time) AS MonitorDate,
IF(MIN(TIME(acc_monitor_log.time)) < '13:00:00',MIN(TIME(acc_monitor_log.time)),'Pending...') AS TimeIn,
MAX(TIME(acc_monitor_log.time)) AS TimeOut,
userinfo.name,userinfo.lastname FROM acc_monitor_log,userinfo
WHERE acc_monitor_log.pin = userinfo.badgenumber AND acc_monitor_log.door_id = 6 AND acc_monitor_log.verified NOT LIKE '%200%'AND DATE(acc_monitor_log.time) LIKE '$time1%' AND acc_monitor_log.pin LIKE '%$person2%'
GROUP BY acc_monitor_log.pin, MonitorDate, userinfo.name, userinfo.lastname ORDER BY MonitorDate, acc_monitor_log.pin ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$Num_Rows = mysql_num_rows($objQuery);
}
<div id="left"><a href="1234.php?timein=<?=$Result["TimeIn"];?>&timeout=<?=$Result["TimeOut"];?>
&person=<?=$Result["pin"];?>" target="new"><b>Export To Excel</b></a>
if(isset($_POST['search']) || isset($_POST['search1'])){
$i=1;
while($Result = mysql_fetch_array($objQuery))
{
?>
<tr >
<td><center><?=$i;?></center></td>
<td width="105"><center><?=$Result['pin'];?></center></td>
<td width="349"><center><? echo $Result['name'];?><? echo $Result['lastname'];?></center></td>
<td width="120"><center><?=$Result['MonitorDate'];?></center></td>
<td width="120"><center><? if($Result['TimeIn'] > '08:16:00')
{echo "<font color=\"#FF0000\"/><b/>".$Result['TimeIn'];}
else{echo "<font color=\"#00CC00\"/><b/>".$Result['TimeIn'];}?></center></td>
<td width="120"><center><? if($Result['TimeOut'] < '13:00:00')
{echo "<font color=\"#FF9900\"/><b/>Pending...";}
else {echo "<font color=\"#00CC00\"/><b/>".$Result['TimeOut'];}?></center></td>
</tr>
<?
$i++;
}
}
?>
1234.php Code (PHP)
<?
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="testing.csv"');
$host="localhost";
$username="root";
$password="1234";
$db="zkeco_db";
mysql_connect( $host,$username,$password) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
echo "PersonalID,Name,Date,TimeIn,TimeOut,ReMark\n";
$sql = "SELECT acc_monitor_log.pin,DATE(acc_monitor_log.time) AS MonitorDate,
IF(MIN(TIME(acc_monitor_log.time)) < '13:00:00',MIN(TIME(acc_monitor_log.time)),'Pending...') AS TimeIn,
IF(MAX(TIME(acc_monitor_log.time)) > '13:00:00',MAX(TIME(acc_monitor_log.time)),'Pending...') AS TimeOut,
userinfo.name,userinfo.lastname FROM acc_monitor_log,userinfo
WHERE acc_monitor_log.pin = userinfo.badgenumber AND acc_monitor_log.door_id = 6 AND acc_monitor_log.verified NOT LIKE '%200%'AND DATE(acc_monitor_log.time) BETWEEN '".$_GET['timein']."' AND '".$_GET['timeout']."' AND acc_monitor_log.pin LIKE '".$_GET['person']."'
GROUP BY acc_monitor_log.pin, MonitorDate, userinfo.name, userinfo.lastname ORDER BY MonitorDate, acc_monitor_log.pin";
$dbquery = mysql_query($sql)or die(mysql_error());
$num_rows = mysql_num_rows($dbquery);
$i=0;
while ($i < $num_rows)
{
$result= mysql_fetch_array($dbquery);
echo "$result[pin],$result[name],$result[MonitorDate],$result[TimeIn],$result[TimeOut],\n";
$i++;
}
?>