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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
aboo_sConnect With a Mentor Commented:
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
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
All Courses

From novice to tech pro — start learning today.