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.

 

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.