[英]query a mysql table for rows that have the same month value and store as a php array for later use displaying them on a calendar
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. 该主题基本上将其总结出来,但是我正在为客户端的php开发日历,该客户端应该从表中提取事件并在适当的单元格中显示它们。
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: 并最终输出类似这样的内容而不会命中数据库31次:
day1.
title / desc
day2.
title / desc <br>
title / desc
day3.
title / desc
you can do one query to get all the events in this mounth, 您可以执行一次查询以获取此Mounth中的所有事件,
like you write 就像你写
select day, title, desc from mytable
where month = $month and year = $year order by day asc
and in the foreach loop on the results, store it in array like 并在结果的foreach循环中,将其存储在数组中,例如
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$events[$row['day']][] = $row;
}
so in the end of the loop you have array $events, where every entry contain an array of the events in this day. 因此,在循环结束时,您将获得数组$ events,其中每个条目都包含当天的事件数组。
like $events[1], $events[2] ....
如
$events[1], $events[2] ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.