php - Gathering rows to 1 row and adding column -


hello learning programming , working on project of php , mysql, have problem.

what doing have table called marks , every time people add mark student, add column table, table looks this:

|------------------| |  subject | marks | |------------------| |   math   |  16   | |  english |  18   |  |  history |  15   |  |  math    |  14   |   |  english |  20   |   |------------------| 

but want change when treat it:

|-------------------------| |   math   |  16   |  14  | |  english |  18   |  20  | |  history |  15   |      | |-------------------------| 

how can mysql's query, or php if needed?

well final goal make html table know how it.

i sorry if looked simple, beginner @ databases , programming , apologize if title confuses guys.

you can try

select subject, group_concat(marks order marks) marks   table  group subject  order subject 

it give 2 columns, 1 comma-separated list of subjects.

english 18, 20 history 15 math    14, 16 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -