954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

group by queries in PHP

Hi

Im creating a list of tutorials on my website and I want to group them by the designer. Is it possible, to write a MySQL query which will function on a PHP website which prints the designer name once and then lists all of his tutorials underneath... in one query? and then does it for all of the designers listed...

I can do it with multiple queries, but am looking for a faster solution...

Thanks
lworks

lifeworks
Junior Poster
145 posts since Nov 2007
Reputation Points: 15
Solved Threads: 2
 

SQL queries only return two-dimensional tables, so if you want to do that, you would have to get the output somewhat like:

+-----------+-----------+
| Designer  | Article   |
+-----------+-----------+
| Designer1 | Article1  |
| Designer1 | Article2  |
| Designer2 | Article1  |
| Designer2 | Article1  |
+-----------+-----------+

If you could arrange it so that the "Designer" in that output was an integer rather than a string, that would be much better. (A lot less wasted resources on repeated data.)

I would probably start by querying for the designer names and their IDs (assuming you assigned each of them a unique ID?), and then query for a list, like that one, using the IDs as the "Designer" column. And then simply match the IDs when I print the list.

Atli
Posting Pro
540 posts since May 2007
Reputation Points: 93
Solved Threads: 70
 

Hi

Thanks for the input, Ill probably go with that,

lworks

lifeworks
Junior Poster
145 posts since Nov 2007
Reputation Points: 15
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You