Gossamer Forum
Home : General : Databases and SQL :

PHP / Mysql Query to group by company name / print company employees

Quote Reply
PHP / Mysql Query to group by company name / print company employees
Hi there,

Going round in circles due to being slightly inept at php / mysql!

I have one very simple Mysql table called 'people' populated with employee and address information.
Fields are;
first
last
company
cell
email
address_1
address_2

I want to produce a loop? in PHP which prints out and groups records by the company field like so;
I don't want to print multiple copies of the Company records each time to save space in the final PDF I am creating.


=========================================
Bobs Widgets (from company field)
24 Madison Avenue (from address_1 field)
---------------------------------------------------------------------
John Doe, Tel: 123 345, Cell: 188 456 (These are the employees from Bobs Widgets)
Sam Smith, Tel: 444 3456, Cell: 728 129
=========================================
Cadbury Chocolate Limited (from company field)
23 Caramel Street (from address_1 field)
---------------------------------------------------------------------
Bob Smythe, Tel: 876 442, Cell: 123 456 (These are all of the lucky employees from Cadbury Chocolate Limited)
Sarah Dickenson, Tel: 154 3456, Cell: 723 129
Darren Johnson, Tel: 1234, Cell: 8232 9323
=========================================
repeat until we have displayed all people.....

The loop also needs to then print out people where there is no company listed (i.e. freelancers etc).

Any help would be appreciated...

Best wishes,

Piers
Subject Author Views Date
Thread PHP / Mysql Query to group by company name / print company employees Piers1 13362 Nov 8, 2009, 2:16 AM
Thread Re: [Piers1] PHP / Mysql Query to group by company name / print company employees
Andy 12988 Nov 8, 2009, 2:39 AM
Thread Re: [Andy] PHP / Mysql Query to group by company name / print company employees
Piers1 12995 Nov 8, 2009, 3:02 AM
Post Re: [Piers1] PHP / Mysql Query to group by company name / print company employees
Andy 12918 Nov 8, 2009, 3:10 AM