How to grab query result to include in mail body

I am doing a query in the db to find all the items bought by a member, to do that I'm using a while loop and I have no problem to build the list on the webpage.

My question is how can I include that list in an email (invoice) sent to the member, obviously I can query the db in the email to rebuild the list in the message.
LVL 28
gamebitsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aboo_sCommented:
You say you can display them with no problem, then I suggest
you do the following $merchandise=$your_2b_displayed_query then $message=$merchandise
and email that message as html using php mail, you can look how to use it in google !
0
gamebitsAuthor Commented:
Not quite, because when it is displayed on the screen the script went through iteration of the loop, if I have 3 items to invoice the script ran through the while loop 3 times, I need to be able to get those 3 items (or 1 or 20 who knows) and save them in a variable to be sent in the email body.

I'd like to add also that the 3 items have a title, date purchased and the price.
0
aboo_sCommented:
I think you can store as text in a variable, each iteration will do this
$message=$message."Title: ".$row['title']." Date: ".$row['date']."Price: ".$row['price']."<br>";

Finally send $message via html mail
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

gamebitsAuthor Commented:
This gives me a

Notice: Undefined variable: message in /home... on line 103

But it works
0
aboo_sCommented:
$message="";
$message=$message."Title: ".$row['title']." Date: ".$row['date']."Price: ".$row['price']."<br>";



to get rid of the notice
0
gamebitsAuthor Commented:
Yes, it will stop the notice but it also stop the loop.
0
aboo_sCommented:
Oh yes I forgot to mention
$message='';
will be put before the loop. you can actually define it somewhere at the begening of your code!
0
gamebitsAuthor Commented:
Yes, seems to work now I'll get back to you on this tomorrow :)
0
gamebitsAuthor Commented:
Thank you very much, works like a charm.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.