I know I've seen other posts about this - thanks for your time.
I've got a data table for user comments and want to produce a report by 'category'.
example table:
category | name | date | comment
Cars| bob jones | 09-13-08 | this is my comment today
Boats | dave smith | 09-12-08 | wish I had a boat
Trucks | tom carpenter | 09-12-08 | need a big truck
I need a query that produces a report by 'category', with category heading, then items listed below it.
ex:
Cars
bob jones
Boats
dave smith
Trucks
tom carpenter
Do I need a 'FOREACH' loop to pull the categories as UNIQUE, then a WHILE loop to pull data 'WHERE category = $category'
looking 'round the web for answers, but always get the best ones here.
thanks.
Do I use 'foreach' loop to do this?
Moderator: General Moderators
Re: Do I use 'foreach' loop to do this?
Nope, just a group by clause in your SQL.
Assuming MySQL:
Assuming MySQL:
Code: Select all
SELECT `name`, `category` FROM `table` GROUP BY `category`Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.