paddy_fields Posted March 5, 2014 Share Posted March 5, 2014 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; } Link to comment https://forums.phpfreaks.com/topic/286728-looping-results-into-a-variable-string/ Share on other sites More sharing options...
Psycho Posted March 5, 2014 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; 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 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. 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
Archived
This topic is now archived and is closed to further replies.