Page 1 of 1

Populating an array with multiple values

Posted: Tue Oct 05, 2010 3:04 am
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.

Re: Populating an array with multiple values

Posted: Tue Oct 05, 2010 4:22 am
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.

Re: Populating an array with multiple values

Posted: Tue Oct 05, 2010 4:44 am
by amargharat
replace following line

Code: Select all

$recipient = "$email,";
with

Code: Select all

$recipient .= "$email,";

Re: Populating an array with multiple values

Posted: Tue Oct 05, 2010 5:33 am
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!