Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display mysql data for Current Week in 7 day calendar

Tags:

php

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.

like image 888
Keith Rattray Avatar asked Oct 27 '25 22:10

Keith Rattray


1 Answers

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.

like image 184
Eugen Rieck Avatar answered Oct 29 '25 13:10

Eugen Rieck