I have an indefinite amount of items in an array:
$query = mysql_query("SELECT * FROM orders WHERE orderID = '$orderID'");
while($row = mysql_fetch_array($query)){
$items[] = $row[itemnumber];
$quantity[] = $row[quantity];
$vendoremail[] = $row[vendoremail];
}
The values in the arrays could be something like this:
$items = ("A","B", "C");
$quantity = ("2", "1", "3");
$vendoremail = ("name1@email.com", "name2@email.com", "name1@email.com");
I want to group the data from the same email addresses and send a single email to each address.
So one email gets sent to name1@email.com with the items “A” and “C” and quantity “2” and “3” in the body of the email.
And another email gets sent to name2@email.com with the items “B” and quantity “1” in the body of the email.
Anybody know the best way to accomplish this?
You can group the values into comma-separated strings via
GROUP_CONCAT()and optionally split them back up in PHP:This will produce results like:
In PHP, if you need to you can
explode()the lists back out into arrays to display in the email body.