我是一名新编码员,我正在尝试为学校项目创建假日预订网站。
我正在使用Jquery UI日期选择器,我正在尝试使用日期范围从我的mysql预订表中提取不可用的日期。
我的表格为bookings
我的日期字段为datein
和dateout
示例:
Row 1
2016-12-15 to 2016-12-18
Row 2
2017-01-15 to 2017-01-18
Next Row Etc...
Desired Output
2016-12-15
2016-12-16
2016-12-17
2016-12-18
2017-01-15
2017-01-16
2017-01-17
2017-01-18
然后使用PHP将它们回显到像这样的json数组中:
["2016-12-15", "2016-12-16", "2016-12-17", "2016-12-18", "2017-01-15", "2017-01-16", "2017-01-17", "2017-01-18"]
如果我的问题不明确但我只是在学习,那么感谢任何可能有所贡献的人道歉。
答案 0 :(得分:0)
我认为(除了数组部分)这里是MYSQL查询。
mysql_select_db($database, $connection);
$query_rsunavaildates = "select selected_date from
(select adddate('1970-01-01',t4*10000 + t3*1000 + t2*100 + t1*10 + t0) selected_date from
(select 0 t0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
(select 0 t1 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
(select 0 t2 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
(select 0 t3 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
(select 0 t4 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v,
bookings
where selected_date between datein and dateout
ORDER BY selected_date ASC";
$rsunavaildates = mysql_query($query_rsunavaildates, $connection) or die(mysql_error());
$row_rsunavaildates = mysql_fetch_assoc($rsunavaildates);
$totalRows_rsunavaildates = mysql_num_rows($rsunavaildates);
如果任何人可以帮助json数组我会很感激。我可以使数组回显,但格式不正确。我需要输出[" 2015-01-02"," 2015-01-03"," etc"]