简体   繁体   English

如何在PHP中使用foreach循环MYSQL月份在+1月份中添加月份?

[英]How to use foreach loop MYSQL month at to add month to +1 month in PHP?

I coding MYSQL (reference code to https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all ) to : 我将MYSQL(参考代码为https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all )编码为:

SELECT * FROM [Orders]
WHERE OrderDate LIKE '1996-01-%'

Present result only to show OrderDate of 1996-01-01 to 1996-01-31. 当前结果仅显示1996年1月1日至1996年1月31日的OrderDate。

I want result to loop MYSQL month to +1 month in PHP. 我希望结果在PHP中将MYSQL循环到+1个月。

Example to real result : 实际结果示例:

show OrderDate of 1996-02-01 to 1996-02-28 显示1996-02-01至1996-02-28的OrderDate
show OrderDate of 1996-03-01 to 1996-03-31 显示1996-03-01至1996-03-31的OrderDate
... ...
show OrderDate of yyyy-mm-dd to yyyy-mm-dd 显示yyyy-mm-dd的OrderDate

you can use like this after that you can merge data at programming end 您可以像这样使用,之后可以在编程结束时合并数据

select *,max(case when month(OrderDate)=1 then OrderDate end) Jan,
max(case when month(OrderDate)=2 then OrderDate end) Feb,
max(case when month(OrderDate)=3 then OrderDate end) Mar,
max(case when month(OrderDate)=4 then OrderDate end) Apr
from Orders
group by month(Orders.OrderDate)`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM