Siggles Posted July 18, 2008 Share Posted July 18, 2008 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 More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 Please show us the code you've tried. Ken Link to comment https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/#findComment-593265 Share on other sites More sharing options...
Siggles Posted July 18, 2008 Author Share Posted July 18, 2008 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? Link to comment https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/#findComment-593269 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 whack a . in front of the = $allemails .= "Misa Prediction League <".$row['email'].">, "; Link to comment https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/#findComment-593270 Share on other sites More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 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 Link to comment https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/#findComment-593271 Share on other sites More sharing options...
Siggles Posted July 18, 2008 Author Share Posted July 18, 2008 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. ?? Link to comment https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/#findComment-593330 Share on other sites More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 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 Link to comment https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/#findComment-593364 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 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); ?> Link to comment https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/#findComment-593371 Share on other sites More sharing options...
Siggles Posted July 18, 2008 Author Share Posted July 18, 2008 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. Link to comment https://forums.phpfreaks.com/topic/115401-solved-populating-a-variable-from-dbase/#findComment-593387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.