How to group data in PHP inside the while loop

Posted by christian on Stack Overflow See other posts from Stack Overflow or by christian
Published on 2010-05-21T17:07:53Z Indexed on 2010/05/21 17:10 UTC
Read the original article Hit count: 345

Filed under:
|

I query in a database and loop the result using while and heres the sample data retrieve:

echo $db->f("FirstName")."===".$db->f("Question")."=".$db->f("Answer")."<br>";

Michael===Q2=allergy
Michael===Q2=Hives
Michael===Q6=A lot
Michael===Q8_A=Daktacort
Michael===Q1=Itch
Michael===Q5=Smoke
Michael===Q8_A=Diprogenta
Christian===Q1=Stuffy
Christian===Q6=A lot
Christian===Q1=Clear
Christian===Q5=Pollen

How can I group them according to name and to their Q value? I want something like this result:

Name          Q1           Q2                         ..... so on and so fort.
Michael      Itch          Hives, Allergy
Christian    Stuffy 

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql