php - Display Two row data in one table TD -


hello please me following problem

mysql data table

sno name    subject marks  1   test1   sub1    20 2   test1   sub2    20 3   test1   sub3    20 4   test1   sub4    20 5   test1   sub5    20 6   test2   sub1    30 7   test2   sub2    30 8   test2   sub3    30 9   test2   sub4    30 10  test2   sub5    30 11  test3   sub1    40 12  test3   sub2    40 13  test3   sub3    40 14  test3   sub4    40 15  test3   sub5    40 

i want display this

sno name    marks 1   test1   100     sub1    20     sub2    20     sub3    20     sub4    20     sub5    20 2   test2   150     sub1    30     sub2    30     sub3    30     sub4    30     sub5    30 3   test3   200     sub1    40     sub2    40     sub3    40     sub4    40     sub5    40 

is possaible in mysql php.

two ways of doing this

1) find unique names , sum of marks

select name  heading, sum(marks) total table group name 

and iterate through results , query records matching name

select * table name = $result['heading'] 

2) records, iterate through results group them

select * table  $headings = []; $children = []; foreach($allrecords $result) {     if (!in_array($result['name'], $headings)     {          $headings[$result['name']]['name'] = $result['name'];     }     if (isset($headings[$result['name']]['marks']))     {         $headings[$result['name']]['marks'] += $result['marks']     }     else     {         $headings[$result['name']]['marks'] = $result['marks']      }     $children[$result['name']][] = $result; } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -