programguru Posted March 24, 2010 Share Posted March 24, 2010 I am simply trying to store the full results of my while loop in a variable to store into a variable for a mail() script I am writing. while(list($key, $val) = each($_POST)) { "<strong>$key</strong> => $val<br />"; } $message = $while_full_result; echo $message; This should echo the same output as the while loop natively does. But I cannot get this to work properly. Thanks for any advice. Link to comment https://forums.phpfreaks.com/topic/196425-while-loop-store-data-in-variable-to-echo-outside-of-loop/ Share on other sites More sharing options...
o3d Posted March 24, 2010 Share Posted March 24, 2010 $while_full_result=''; while(list($key, $val) = each($_POST)) { $while_full_result .= "<strong>$key</strong> => $val<br />"; } Link to comment https://forums.phpfreaks.com/topic/196425-while-loop-store-data-in-variable-to-echo-outside-of-loop/#findComment-1031324 Share on other sites More sharing options...
programguru Posted March 24, 2010 Author Share Posted March 24, 2010 o3d, Thanks. Worked like a charm. I guess I have a lot to learn with this specific type of loop, because I can't get this to work with my table output structure now. It's only echoing the key value pair from the form: $while_full_result=''; while(list($key, $val) = each($_POST)) { $while_full_result = "<table border=\"1\">"; $while_full_result .= "<tr><td>$key</td><td>$val</td></tr>"; $while_full_result .= "</table>"; } $message = $while_full_result; Link to comment https://forums.phpfreaks.com/topic/196425-while-loop-store-data-in-variable-to-echo-outside-of-loop/#findComment-1031341 Share on other sites More sharing options...
programguru Posted March 24, 2010 Author Share Posted March 24, 2010 o3d, Thanks. Worked like a charm. I guess I have a lot to learn with this specific type of loop, because I can't get this to work with my table output structure now. It's only echoing the key value pair from the form: $while_full_result=''; while(list($key, $val) = each($_POST)) { $while_full_result = "<table border=\"1\">"; $while_full_result .= "<tr><td>$key</td><td>$val</td></tr>"; $while_full_result .= "</table>"; } $message = $while_full_result; I actually had luck echoing it to the page, but I could not get it to print in the email????? $while_full_result=''; while(list($key, $val) = each($_POST)) { $while_full_result .= "<tr><td>$key</td><td>$val</td></tr>"; } $message = "<table>$while_full_result</table>"; echo $message; // Mail it mail($to, $subject, $message, $headers); Link to comment https://forums.phpfreaks.com/topic/196425-while-loop-store-data-in-variable-to-echo-outside-of-loop/#findComment-1031346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.