Jump to content

While Loop - Store Data in Variable to Echo Outside of Loop


programguru

Recommended Posts

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.

 

 

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;

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.