[英]Display mysql data for Current Week in 7 day calendar
I need a guiding hand, how do I display the " current week" starting on Monday , in a 7-day calendar by a 7-room grid, for a small theatre I volunteer at, various voluntary town groups use the rooms. 我需要一个引导手,我如何在星期一开始的7天日历中显示“当前周”,对于我自愿参加的一个小剧场,各个自愿城镇团体使用房间。
My database name=rooms, table=roomdiary, it has 7 fields (field_1 to Field_7). 我的数据库名称= rooms,table = roomdiary,它有7个字段(field_1到Field_7)。
I can populate each day with data from the dbase using the "Select" query & php isset code where required. 我可以使用“选择”查询和php isset代码在每天填充来自dbase的数据。 But I am stumped on how to correctly display only " current week " data in the right room on right day.
但我很难知道如何在正确的日子里正确显示正确的房间里的“当前周”数据。 >
>
////// Mon... Tues . Wed .. Thu .. Fri . Sat .. Sun room 1 data . data . data . data . data data . data room 2 data . data . data . data . data data . data room 3 data . data . data . data . data data . data room 4 data . data . data . data . data data . data room 5 data . data . data . data . data data . data room 6 data . data . data . data . data data . data room 7 data . data . data . data . data data . data
I apologise for having not posted any code, as I thought any generic advice would be more than helpful and help me learn. 我为没有发布任何代码而道歉,因为我认为任何通用建议都会有所帮助并帮助我学习。 Any guidance would be appreciated.
任何指导将不胜感激。
Redesign Your database, make table rooms (room_id, room_name) and table schedule (room_id, date, data, week_nr, year) 重新设计您的数据库,制作餐厅(room_id,room_name)和餐桌时间表(room_id,date,data,week_nr,year)
Always write with date also week_nr to database - date('W', timestamp) 总是用date_nr写入数据库 - 日期('W',时间戳)
If you don't want to store week_nr in database, then try strtotime('Last monday', timestamp) and strtotime('Next sunday', timestamp) and select range from database dates 如果您不想在数据库中存储week_nr,请尝试strtotime('Last monday',timestamp)和strtotime('Next sunday',timestamp)并从数据库日期中选择范围
I recommend you split this problem in two 我建议你把这个问题分成两部分
The first point is quite easy using PHP's date()
or getdate()
functions, the second can be achieved by SELECT ... WHERE datecolumn BETWEEN monday_date AND sunday_date
. 第一点很容易使用PHP的
date()
或getdate()
函数,第二点可以通过SELECT ... WHERE datecolumn BETWEEN monday_date AND sunday_date
来实现。
This helps modularize your program: What if you want to add future display options? 这有助于模块化您的程序:如果您想添加将来的显示选项怎么办? What if your theater decides not to play on mondays?
如果你的剧院决定不在星期一演出怎么办?
Additionally I recommend against harcoding your 7 rooms into 7 fields: A relational approach would have a "rooms" table (currently with 7 rows) and a "performances" table linking a room and a date. 此外,我建议不要将7个房间分成7个字段:关系方法会有一个“房间”表(目前有7行)和一个连接房间和日期的“表演”表。 If you add a "programs" table and also link it to the "performances" table, you already get the program data for free.
如果添加“程序”表并将其链接到“性能”表,则您已经免费获得程序数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.