How can I put rows of MySQL data under the appropriate titles using PHP?

Posted by sfarbota on Stack Overflow See other posts from Stack Overflow or by sfarbota
Published on 2010-03-08T08:26:45Z Indexed on 2010/03/08 8:36 UTC
Read the original article Hit count: 321

Filed under:
|
|
|

I have the following MySQL table structure:

num field company phone     website

1   Gas   abcd    123456789 abcd.com
2   Water efgh    987654321 efgh.com
3   Water ijkl    321654987 ijkl.com
4   Heat  mnop    987654321 mnop.com
5   Gas   qrst    123789654 qrst.com
...

Is it possible with PHP (maybe using some mixture of GROUP_BY and ORDER_BY) to echo the data to the screen in the following format:

Gas:
abcd       qrst
123456789  123789654
abcd.com   qrst.com

Water:
efgh       ijkl
987654321  321654987
efgh.com   ijkl.com

Heat:
mnop
321654987
mnop.com

The exact format of it isn't important. I just need for the different rows of data to be listed under the appropriate field with none of the fields repeated. I've been trying to figure this out for a while now, but I'm new to PHP and I can't seem to figure out how to do this, if it's even possible, or if there's a better way to organize my data to make it easier.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql