Jump to content

Archived

This topic is now archived and is closed to further replies.

piznac

CS Array from MySql results

Recommended Posts

Ok,.. I would have thought this would have been simple,.. but I can't seem to pull it off. I have a list of email addys store in a table and I need to pull those results. Then place them as a comma seperated string in a variable. Here is what I have so far:

[code]<?php
mysql_select_db($database_pms, $pms);
$query = sprintf("SELECT email FROM access");
$em = mysql_query($query) or die(mysql_error());

$array = array($em);
$comma_separated = implode(",", $array);

echo $comma_separated;


?>[/code]

this is simply returning: Resource id #4

I had it set up like this:
[code]<?php
mysql_select_db($database_pms, $pms);
$query = sprintf("SELECT email FROM access");
$em = mysql_query($query) or die(mysql_error());

while ($array= mysql_fetch_assoc($em)) {
        $try2 = "$array[email]\n";
$try3 = explode(" ",$try2);
echo $try3[0];
$fnamec=str_replace(' ', ',', $try3[0]);
echo $fnamec;
}
?>[/code]
I can get it to display the array,.. but not comma seperated and not where I can use it

Share this post


Link to post
Share on other sites
[code]
<?php
mysql_select_db($database_pms, $pms);
$query = sprintf("SELECT email FROM access");
$em = mysql_query($query) or die(mysql_error());
$myarray = array();
while($row = mysql_fetch_array($em))
  $myarray[] = $row['email'];

$comma_seperated = implode(",", $myarray);
echo $comma_separated;
?>
[/code]

Kind of a mixture of the two that you had.

Share this post


Link to post
Share on other sites
ahhh it would appear the variable was misspelled,. thanks for the help man!!:)

Share this post


Link to post
Share on other sites

×

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.