jeff5656 Posted June 17, 2009 Share Posted June 17, 2009 Instead of echoing out this list of records, I want to put everything inside this while loop into $message so I can email the list. How do I do this? Here's the code that echoes it out to the screen: $query2 = "SELECT * FROM `gpu` WHERE `signoff_status` = 'a' and `attg` = '". $whoto ."' "; $result2 = mysql_query ($query2) or die ("Invalid query: " . mysql_error ()); while ($row2 = mysql_fetch_assoc ($result2)) { echo "Patient:". $row2['patient'] . " MRN: " . $row2['mrn']; <br> } Link to comment https://forums.phpfreaks.com/topic/162629-put-while-loop-contents-into-one-variable/ Share on other sites More sharing options...
rhodesa Posted June 17, 2009 Share Posted June 17, 2009 <?php $message = ""; $query2 = "SELECT * FROM `gpu` WHERE `signoff_status` = 'a' and `attg` = '". $whoto ."' "; $result2 = mysql_query ($query2) or die ("Invalid query: " . mysql_error ()); while ($row2 = mysql_fetch_assoc ($result2)) { $message .= "Patient:". $row2['patient'] . " MRN: " . $row2['mrn'] . "\n<br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/162629-put-while-loop-contents-into-one-variable/#findComment-858314 Share on other sites More sharing options...
jeff5656 Posted June 17, 2009 Author Share Posted June 17, 2009 Ok, will this keep appending the additional records into $message untl the while loop is complete? It won't be that each record will overwrite the value of $message Link to comment https://forums.phpfreaks.com/topic/162629-put-while-loop-contents-into-one-variable/#findComment-858323 Share on other sites More sharing options...
rhodesa Posted June 17, 2009 Share Posted June 17, 2009 nope, the . in the .= appends instead of overwrites. it's shorthand for: $message = $message . "some more text"; Link to comment https://forums.phpfreaks.com/topic/162629-put-while-loop-contents-into-one-variable/#findComment-858327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.