查询 mysql 表中具有相同月份值的行并将其存储为 php 数组以供以后使用在日历上显示它们
这个主题基本上概括了它,但我正在为一个客户端开发一个 php 日历,它应该从表中提取事件并将它们显示在适当的单元格中。
日历表工作正常,但我试图避免的是为该月的每一天进行单独的数据库调用。
我试图找出一种方法,首先将结果存储在数组数组中,然后在创建日历时,每天有事件的日子都会显示该事件的部分数据。
这是我遇到的一个概念问题,我似乎无法解决它。
另外,不确定是否可能。
任何帮助表示赞赏。
谢谢。
例如:
select day, title, desc where month = $month and year = $year order by day asc
最终输出类似这样的内容,而无需访问 DB 31 次:
day1.
title / desc
day2.
title / desc <br>
title / desc
day3.
title / desc
the subject basically sums it up, but i am working on a calendar in php for a client that should pull events from a table and display them in the appropriate cells.
the calendar table is working no prob, but what i am trying to avoid is making a separate DB call for each day of the month.
i am trying to figure out a way to store the results in an array of arrays first, then as the calendar is created, each day that has an event(s) would display some portion of the data for that even there.
it's a conceptual problem i am having and i can't seem to solve it.
also, not sure if it's possible.
any help is appreciated.
thanks.
for example:
select day, title, desc where month = $month and year = $year order by day asc
and ultimately output something like this without hitting the DB 31 times:
day1.
title / desc
day2.
title / desc <br>
title / desc
day3.
title / desc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行一个查询来获取此挂载中的所有事件,
就像您
在结果的 foreach 循环中编写的那样,
将其存储在数组中,就像
这样在循环结束时您有数组 $events,其中每个条目都包含当天事件的数组。
如
$events[1]、$events[2] ....
you can do one query to get all the events in this mounth,
like you write
and in the foreach loop on the results,
store it in array like
so in the end of the loop you have array $events, where every entry contain an array of the events in this day.
like
$events[1], $events[2] ....