Using PHP and MySQL to do some dynamic looping
Posted on 2004-10-11
I was wondering if somebody might have a solution for this problem, which I'm sure comes up often.
I have a table where "Reminders" are entered throughout the day. Each Reminder has a mailTo address, that is completely arbitrary and not linked to anything in the database. Once per day, I have to go to this table and summarize all the reminders for each UNIQUE email address - then send the summary to the that recipient.
In other words, if firstname.lastname@example.org has 10 Reminders in the the Reminders table, I need to compile the bodies of all 10 reminders and mail them to email@example.com in a SINGLE email message. Naturally, just looping over the entire table and sending 10 different messages to firstname.lastname@example.org is cake.
I'm kind of stumped, and sort of embarrassed since this seems like it should be easy! I've tried using things such as UNIQUE and GROUP to arrive at my solution, but nothing has come to me yet.