Hello everyone,

My brain is pickled trying to work this one out so I am hoping someone can help.

I have a database with a set of orders. Each row of data contains (amongst others) an order number, an item name and a seller email address.

I have queried the database to retrieve a set of rows by order number i.e. Select all rows with order number 123
What I would like to do with this result is sort it by the shared value, the seller email.

For instance, against order number 123 there might be the following results:

item: blue widget
seller_email: bob@myemail.com

item: red widget
seller_email: charles@myemail.com

item: green widget
seller_email: bob@myemail.com

I now want to set up a function to email the seller with the items from the order but I only want to email the items that are relevant to them. So in the example above there are 2 items to order from bob (blue widget and green widget) but I only want to email him once with both items. I then also need to email charles the order for the red widget.

So what I need to be able to do is take my array and then email each set of items according to the seller email.
i.e. For each individual seller email with the order number 123, email these items.

I hope that makes sense but please ask away if you have any questions.

Thanks in advance