RE: [PHP] How Can I Generate an Email List from a MySQL Table
| From: | Roger Lewis | Date: | Mon, 19 Aug 2002 03:05:54 +0000 |
| Subject: | RE: [PHP] How Can I Generate an Email List from a MySQL Table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-113173@lists.php.net to get a copy of this message | ||
On Sat, 17 Aug 2002 20:10:02 -0700
"Roger Lewis" <re.lewis@attbi.com> wrote:
> My problem is how do you create the variable, $to, from the MySQL table so
> that it contains all of the addresses separated by commas.
Daren Cotter [mailto:daren_cotter@yahoo.com] responded
Saturday, August 17, 2002 8:42 PM
> // Query database
> $result = mysql_query("SELECT email_address FROM users
> WHERE is_subscribed = 'Y'", $link);
> while ($row = mysql_fetch_array($result)) {
> mail($row["email_address"], $SUBJECT, $BODY,
> $HEADER);
> }
> mysql_free_result($result);
Darren,
Thanks a lot. This works fine. Please have a virtual beer on me! :)
To Chris Knipe [mailto:savage@savage.za.org] who responded
> $to = '';
> while ($blah = mysql_fetch_row($ref)) {
> $to =+ $blah['address'];
> };
I tried this, but I got an index error. It doesn't understand 'address'
and I couldn't figure out what was going on.
To Kevin Waterson who responded
> simply create your array and use implode.
> There is an example of comma seperated lists in the manual
> http://www.php.net/manual/en/function.implode.php
I like this method because it seems more elegant than above, but I don't
seem to be able to create the array properly.
I tried the following as well as many other combinations, but couldn't get
anything to work:
$sql = "SELECT email_address FROM users WHERE is_subscribed = 1";
$result = mysql_query($sql);
$to = implode(",", mysql_fetch_array($result));
Thanks again everyone for your help
Roger Lewis
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com