dongyan2267 2012-11-27 13:29
浏览 89
已采纳

在7天日历中显示当前周的mysql数据

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.
My database name=rooms, table=roomdiary, it has 7 fields (field_1 to Field_7).

I can populate each day with data from the dbase using the "Select" query & php isset code where required. 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.

  • 写回答

2条回答 默认 最新

  • dongluan2612 2012-11-27 13:44
    关注

    I recommend you split this problem in two

    1. Calculate start of display period (="Which date is the current Monday")
    2. Select and display your records

    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.

    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. If you add a "programs" table and also link it to the "performances" table, you already get the program data for free.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?