php - Mysql query dinamic rows as fields -


i have website uses php , mysql. these tables:

users:

id | name ---+--------- 1  | yamato 2  | joshua 3  | rebecca 4  | brian 5  | clark ....and more 

tasks:

id | name ---+--------- 1  | visit 2  | travel 3  | office 4  | customer meeting 

this table registers user's activities:

activities

id | user_id| task_id | date  ---+--------+---------+----------- 1  | 1      | 1       | 2017-05-02 2  | 1      | 2       | 2017-05-01 3  | 2      | 2       | 2017-05-03 4  | 3      | 3       | 2017-05-04 5  | 4      | 4       | 2017-05-05 6  | 1      | 1       | 2017-05-06 7  | 1      | 1       | 2017-05-07 ...and more 

what trying count number of activities user, this:

name              |  yamato | joshua | rebbeca | brian | clark |...and more ------------------+---------+--------+---------+-------+-------+- visit             |    3    |   0    |    0    |  0    |  0    | travel            |    1    |   1    |    0    |  0    |  0    | office            |    0    |   0    |    1    |  0    |  0    | customer meeting  |    0    |   0    |    0    |  1    |  0    | 

but problem can add users , tasks, should dinamic, not quite sure how it.

thank you.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -