Hiii我有两个不同的表
我想从两个表中获取数据,例如(21-11-2016到27-11-2016)之间的日期并输出这样的内容 Timesheet
我试过以下查询请检查。
<?php
$staff_data = mysql_query("SELECT * FROM staff_rotas LEFT JOIN staff_login ON
(DATE(staff_rotas.startDateTime) = DATE(staff_login.actual_startDateTime))
WHERE staff_rotas.staff_id = '123' AND DATE_FORMAT(staff_rotas.startDateTime,'%Y-%m-%d')
BETWEEN '" . $date_from . "' AND '" . $date_to . "'
UNION
SELECT * FROM staff_rotas RIGHT JOIN staff_login ON (
DATE(staff_login.actual_startDateTime) = DATE(staff_rotas.startDateTime))
WHERE staff_login.staff_id = '123' AND
DATE_FORMAT(staff_login.actual_startDateTime,'%Y-%m-%d') BETWEEN '" . $date_from . "' AND '" . $date_to . "'
ORDER BY `startDateTime` DESC")
while($data = mysql_fetch_object($staff_data)){
/*html table to show data ......
...
...
*/
}
?>