Jump to content


Photo

CS Array from MySql results


  • Please log in to reply
3 replies to this topic

#1 piznac

piznac
  • Members
  • PipPipPip
  • Advanced Member
  • 261 posts

Posted 20 September 2006 - 12:40 PM

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:

<?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;


?>

this is simply returning: Resource id #4

I had it set up like this:
<?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;
		}
?>
I can get it to display the array,.. but not comma seperated and not where I can use it

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 20 September 2006 - 01:35 PM

<?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;
?>

Kind of a mixture of the two that you had.

Info: PHP Manual


#3 piznac

piznac
  • Members
  • PipPipPip
  • Advanced Member
  • 261 posts

Posted 20 September 2006 - 01:43 PM

hmm,.. Im getting no results returned with this :-\

#4 piznac

piznac
  • Members
  • PipPipPip
  • Advanced Member
  • 261 posts

Posted 20 September 2006 - 02:02 PM

ahhh it would appear the variable was misspelled,. thanks for the help man!!:)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users