Jump to content

[SOLVED] Populating a variable from dbase.


Siggles

Recommended Posts

Problem a simple question. I am trying to create a variable with a long text string to use in a bcc field in an e-mail script. the emails are being pulled from a dbase. So for example I have...

 

 $result = mysql_query("SELECT email FROM users");

 

then I have to get these email address into this form...

 

Email subject <email address>,

 

and then the nxt one and so on and so on so it looks a bit like this...

 

Email subject <[email protected]>, Email subject <[email protected]>, Email subject <[email protected]>,

 

How do I get one variable to have all that information? I have tried different ways with a while loop but i cant get it to work.

 

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/
Share on other sites

AT the moment I have...

 

 $result = mysql_query("SELECT email FROM users");
  			while($row = mysql_fetch_array($result)){
  			$allemails = "Misa Prediction League  <".$row['email'].">, ";
  			}

 

but the $allmails vaiable changes each time (I think). Do I need to make an array?

Yes, you need an array, since each time through the loop you're overwriting the one variable. Try:

<?php
$result = mysql_query("SELECT email FROM users");
$tmp = array();
while($row = mysql_fetch_array($result))
    $tmp[] = "Misa Prediction League  <".$row['email'].">";
$allemails = implode((', ',$tmp);
?>

 

Ken

I have this now....

 

 

$result = mysql_query("SELECT email FROM users");
  			while($row = mysql_fetch_array($result)){
  			$allemails .= "Misa Prediction League  <";
  			$allemails .= $row['email'];
  			$allemails .= ">, ";
  			}

but it still shows...

 

Misa Prediction League , Misa Prediction League , Misa Prediction League ,

 

and doesn't include the emails. But if I do echo $row['email']; on its own the emails show. ??

What does it look like when you do a "show source". Remember, that browsers will eat anything between "< >" because they think it's a tag.

 

Also you can try:

<php
echo htmlentities($allemails,ENT_quotes);
?>

to see the value.

 

Ken

I would use what Ken has, as it eliminates the last blank comma. You could try it like this:

 

<?php
$result = mysql_query("SELECT email FROM users");
$tmp = array();
while($row = mysql_fetch_array($result))
    $tmp[] = "Misa Prediction League  <".$row['email'].">";
$allemails = implode((', ',$tmp);
?>

What does it look like when you do a "show source". Remember, that browsers will eat anything between "< >" because they think it's a tag.

 

Also you can try:

<php
echo htmlentities($allemails,ENT_quotes);
?>

to see the value.

 

Ken

 

i think you are right Ken and that could have been my problem when trying things out before. :-) I am just wating for a couple of people to confirm that the mail has arrived but it look sgood.

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.