Populating an array with multiple values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kdidymus
Forum Contributor
Posts: 196
Joined: Tue May 13, 2008 3:37 am

Populating an array with multiple values

Post by kdidymus »

Folks.

Sorry, my mind has gone completely blank here.

What I WANT to do is have my PHP download a list of e-mail addresses from a table named maillist and produce an array called $recipient with all of the values found separated by a comma.

This is the query I am using:

Code: Select all

$query = "SELECT * FROM maillist";
$result = mysql_query($query)
          or die ("Couldn't execute query.");
while ($row = mysql_fetch_assoc($result))
{extract ($row);
$recipient = "$email,"};
But it's only fetching the LAST e-mail address in the table. I want $recipient to be something like joebloggs@aol.com, mike.hunt@sky.com

Numerous e-mail address all separated by a comma.

Any ideas?

Thank you SO much in advance.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Populating an array with multiple values

Post by requinix »

You aren't even using arrays to begin with.

Arrays
Stick all the email addresses into an array, one at a time. When you're done, use implode to add the commas.
amargharat
Forum Commoner
Posts: 82
Joined: Wed Sep 16, 2009 2:43 am
Location: Mumbai, India
Contact:

Re: Populating an array with multiple values

Post by amargharat »

replace following line

Code: Select all

$recipient = "$email,";
with

Code: Select all

$recipient .= "$email,";
kdidymus
Forum Contributor
Posts: 196
Joined: Tue May 13, 2008 3:37 am

Re: Populating an array with multiple values

Post by kdidymus »

Thank you. It works fine now.

The following code works BRILLIANTLY:

Code: Select all

include_once("../*******.inc.php");
$cxn = mysql_connect($host,$user,$password)
       or die ("Couldn't connect to server");
mysql_select_db($database);

$query = "SELECT * FROM maillist";
$result = mysql_query($query)
          or die ("Couldn't execute query.");

while ($row = mysql_fetch_assoc($result))
{extract ($row);
$recipient .= "$email,";}
I'm a very happy man!
Post Reply