我有两个单独的日历:reservation_schedule 和 maintenance_schedule 日历。Reservation_schedule 从保留表中获取数据,maintenance_schedule 从维护表中获取数据。我的目标是将两个日历中获取的数据放入一个日历中。
这是我用于 reservation_schedule 的查询:
SELECT acode
FROM reservation
WHERE month(etd) = '".$month."'
AND dayofmonth(etd) = '".$dayArray["mday"]."'
AND year(etd) = '".$year."'
ORDER BY etd
对于maintenance_schedule:
SELECT DISTINCT s.reg AS 'reg',
a.date AS 'date'
FROM (SELECT Curdate()
+ INTERVAL (a.a + (10 * b.a) + (100 * c.a)) day AS Date
FROM (SELECT 0 AS a
UNION ALL SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
UNION ALL SELECT 7
UNION ALL SELECT 8
UNION ALL SELECT 9) AS a
CROSS JOIN (SELECT 0 AS a
UNION ALL SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
UNION ALL SELECT 7
UNION ALL SELECT 8
UNION ALL SELECT 9) AS b
CROSS JOIN (SELECT 0 AS a
UNION ALL SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
UNION ALL SELECT 7
UNION ALL SELECT 8
UNION ALL SELECT 9) AS c) a
INNER JOIN maintenance_sched s
ON a.date >= s.date_from
AND a.date <= s.date_to
WHERE Month(date) = '".$month."'
AND Dayofmonth(date) = '".$dayArray["mday"]."'
AND Year(date) = '".$year."'
我可以通过使用显示来自它们的UNION
数据,但我希望维护表中的数据以带删除线的字符串形式输出。我在这段代码中输出查询结果:
$chkEvent_res = mysql_query($chkEvent_sql) or die(mysql_error());
if (mysql_num_rows($chkEvent_res) > 0) {
$event_title = "<br/>";
while ($ev = mysql_fetch_array($chkEvent_res)) {
$event_title .= stripslashes($ev["reg"])."<br/>";
//$event_title .= "<del>".stripslashes($ev["acode"])."</del><br/>";
}
mysql_free_result($chkEvent_res);
} else {
$event_title = "";
}
如果我将查询与 一起使用UNION
,我无法将维护的输出字符串设置为带有删除线,因为它运行查询一次。如何实现从维护表中获取的数据以删除线输出?我应该去查询一个UNION
吗?如果我这样做,我怎样才能分离来自维护表和保留表的数据?如果我去分离查询,我该如何运行它?应该是这样的$chkEvent_res = mysql_query($chkEvent_sql1) and mysql_query($chkEvent_sql2) or die(mysql_error());
吗?请帮忙,谢谢。