Jump to content

[SOLVED] Can't get commas to print


Kane250

Recommended Posts

I'm pulling rows of email addresses from a database and I want them to be seperated by commas. For some reason I can't get it right. If I use mysql_fetch_array It seperates them but it inserts each one twice. If I use mysql_fetch_assoc, it only inserts them once, but no commas. Ideas?

 

<?php// Get the results from the database
$mlistcontacts = mysql_query('SELECT email FROM emaillist');

while($mlistcontacts2 = mysql_fetch_array($mlistcontacts)){
$massmail = implode(',', $mlistcontacts2);
print ($massmail);
}?>

Link to comment
https://forums.phpfreaks.com/topic/105212-solved-cant-get-commas-to-print/
Share on other sites

mysql_fetch* only retreives one row at a time with each field represnted by an array element. You want...

 

<?php// Get the results from the database

$mlistcontacts = mysql_query('SELECT email FROM emaillist');

while($mlistcontacts2 = mysql_fetch_assoc($mlistcontacts)) {
  $massmail[] = $mlistcontacts2['email'];
}
print implode(',',$massmail);

}

?>

Archived

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

×
×
  • 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.