php - PIVOT Table making columns dynamic -


i know kind of question might have been asked before.

but self not sure if doing right way have ask.

i want below table in output

 empid   name          desig     year       q1       q2      q3       annual  --------------------------------------------------------------------------------- 1       haider          0       2016      setup    setup    setup     anotherstring 2       arif            1       2016      setup    setup    setup     anotherstring 

but tables have in db are.

employee table:

 empid   name          desig  ------------------------------- 1       haider          0    2       arif            1 

appraisal table

 id      title     ----------------- 1       q1   2       q2 3       q3 4       annual       

the values in appraisal table columns in output table(first table).

i don't understand how can pivot. have seen examples not sure how have table setup this.

plus there no year information in table. year displayed current year against every employee.

this kinda query tried work on. don't know how join other table there no employee information there or anything.

select    *    employee e     inner join employment et      on et.`employee_id` = e.`employee_id`      , et.`trashed` = 0     , et.`current` = 1    e.`enrolled` = 1    , e.`trashed` = 0    , e.`employee_id` in (8,1,3,17,6,19,23) 

=-=-=-=-=-==-==-=-

update

here have tried far. when run it, no table ??

  set @sql = null;  select group_concat(distinct appraisaltitle) @sql `ml_appraisal_title` trash = 0;    set @sql = concat('select e.employee_id                     , e.full_name name, ', @sql, '                     employee e                    left join ml_appraisal_title mlpt                      on mlpt.id = e.employee_id                    group e.employee_id');  prepare stmt @sql; execute stmt; deallocate prepare stmt; 

i don't quite full understand it. im keep trying figure out.

=-=-=-=--=-=-=-=-=

update:2

i think reaching somewhere this. xd..

 set @sql = null;  select group_concat(distinct concat('max(if(appraisaltitle=''',appraisaltitle,''', appraisaltitle, null)) ',appraisaltitle )) @sql `ml_appraisal_title` trash = 0;    set @sql = concat('select e.employee_id                     , e.full_name name, ', @sql, '                     employee e                    left join ml_appraisal_title mlpt                      on mlpt.appraisalid = e.employee_id                    group e.employee_id');  prepare stmt @sql; execute stmt; deallocate prepare stmt; 

i got result below result above query. enter image description here

but thing values in columns needs come table. confused how can that. can see in output there setup act link. , can changed other value depending on table.

appraisal notification table

 id      notification ----------------- 1       setup 2       create 3       complete 

how show setup table? can understand need join it.. thinking if can use left join , if values null setup should show. possible?


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -