Kane250 Posted May 12, 2008 Share Posted May 12, 2008 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 More sharing options...
trq Posted May 12, 2008 Share Posted May 12, 2008 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); } ?> Link to comment https://forums.phpfreaks.com/topic/105212-solved-cant-get-commas-to-print/#findComment-538732 Share on other sites More sharing options...
Kane250 Posted May 12, 2008 Author Share Posted May 12, 2008 Perfect! Thank You!!! Link to comment https://forums.phpfreaks.com/topic/105212-solved-cant-get-commas-to-print/#findComment-538737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.