paddy_fields Posted March 5, 2014 Share Posted March 5, 2014 (edited) Hi, I'm creating an email alert and need the entire list of results to be stored in $message so I can use it in the mail() function As the script loops I'm trying to append each result to $message but I can't work out how to do this using the <<< method (I've forgotten what it's called so I can't google it!) I've tried the $x = $x."new data" method but this clearly doesn't work. Can someone point me in the right direction? //display the job results for that particular alert while($row = $jobResult->fetch_assoc()){ $title = $row['title']; $location = $row['location']; $subject = $row['subject']; //begining of HTML message $message = $message.<<<MESSAGE <h3>$title</h3> <p>$location</p> <p>$subject</p> <hr> MESSAGE; } Edited March 5, 2014 by paddyfields Quote Link to comment https://forums.phpfreaks.com/topic/286728-looping-results-into-a-variable-string/ Share on other sites More sharing options...
Solution Psycho Posted March 5, 2014 Solution Share Posted March 5, 2014 That format works for me. Are you getting errors? I didn't do a DB query, but I ran the following and got the expected results for($i=0; $i<5; $i++) { $message = $message.<<<MESSAGE <h3>title{$i}</h3> <p>location{$i}</p> <p>subject{$i}</p> <hr> MESSAGE; } echo $message; Quote Link to comment https://forums.phpfreaks.com/topic/286728-looping-results-into-a-variable-string/#findComment-1471545 Share on other sites More sharing options...
paddy_fields Posted March 5, 2014 Author Share Posted March 5, 2014 Haha, right you are. I wasn't expecting it to work for some reason and so when I got a Notice I assumed the email hadn't sent. Do you know why I'd be getting the notice though? It doesn't display when I simply use $message = <<<MESSAGE Notice: Undefined variable: message in /Users/pat/Sites/recruitment/1_DummySite/email-alert-sandbox.php on line 68 Quote Link to comment https://forums.phpfreaks.com/topic/286728-looping-results-into-a-variable-string/#findComment-1471547 Share on other sites More sharing options...
paddy_fields Posted March 5, 2014 Author Share Posted March 5, 2014 Oh, I know. It's because I haven't defined $message before the first loop. Face... palm. Quote Link to comment https://forums.phpfreaks.com/topic/286728-looping-results-into-a-variable-string/#findComment-1471549 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.