Jump to content

CS Array from MySql results


piznac

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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.