Jump to content

Build a calendar like view


samtwilliams

Recommended Posts

Hi All,

 

Just about to embark on taking some data from a mysql DB and pivoting it into a calendar like view. I'm not php or mysql expert so rather than struggle and take days to complete i'd thought i'd explain what i'm trying to do and see if anyone has done similar or has any code snip its.

 

I have data like this;

 

TaskID|Assigned|DueDate

1|User1|01/01/01

2|User2|02/01/01

 

I want to create a dynamic table that pivots the data so that the next thirty days are put into rows, the users are along the top and the tasks a put in the middle;

 

         User1           User2

Date Task1           Task3

         Task2

Date

Date

Date

 

Has anyone achieved anything similar or recommend the best way to achieve it?

 

 

Link to comment
Share on other sites

This has nothing to do with MySQL. It's a data rendering job.

 

All you have to do is put the data into a more convenient format like a two-dimensional associative array:

[
    'date1' => [
        'user1' => [
            'task1',
            'task2',
            // ...
        ],
        'user2' => [
            // ...
        ],
    ],
    'date2' => [
        // ...
    ],
    // ...
]

Then you can simply iterate over the dates and user to generate your table.

 

As pseudo code

// collect all users separately for easier rendering 
users = []

// load data into new structure
table_data = []
for each row in database_table:
  users[] = row['user']
  table_data[row['date']][row['user']] = row['task']

render_table_headers(users)
for each date, user_tasks in table_data:
  render_date_cell(date)
  for each user in users:
    if user_tasks has key user:
      render_tasks(user_tasks[user])
    else:
      render_empty_cell() 

A quick forum search also helps. This has been discussed to death.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.