jwk811 Posted September 3, 2008 Share Posted September 3, 2008 take a column in db and separate each input with a comma? Quote Link to comment https://forums.phpfreaks.com/topic/122626-separate-by-commas/ Share on other sites More sharing options...
The Little Guy Posted September 3, 2008 Share Posted September 3, 2008 ? explain better. Quote Link to comment https://forums.phpfreaks.com/topic/122626-separate-by-commas/#findComment-633172 Share on other sites More sharing options...
jwk811 Posted September 3, 2008 Author Share Posted September 3, 2008 i want to get a bunch of emails from the database. SELECT email FROM table how can I have it list alll the emails in the database separated by commas? Quote Link to comment https://forums.phpfreaks.com/topic/122626-separate-by-commas/#findComment-633174 Share on other sites More sharing options...
.josh Posted September 3, 2008 Share Posted September 3, 2008 $sql = "selece email from table"; $result = mysql_query($sql); while($r = mysql_fetch_assoc($result)) { $emaillist .= $r['email'] . ","; } Quote Link to comment https://forums.phpfreaks.com/topic/122626-separate-by-commas/#findComment-633202 Share on other sites More sharing options...
DarkWater Posted September 3, 2008 Share Posted September 3, 2008 That'll add an extra , in the final output, CV. =P You may want to put them into an array and implode(). Quote Link to comment https://forums.phpfreaks.com/topic/122626-separate-by-commas/#findComment-633206 Share on other sites More sharing options...
.josh Posted September 3, 2008 Share Posted September 3, 2008 What is it with me and commas today?? you can substr or rtrim the prev code or as darkwater suggested: $sql = "selece email from table"; $result = mysql_query($sql); while($r = mysql_fetch_assoc($result)) { $emails[] = $r['email']; } $emaillist = implode(',',$emails); Quote Link to comment https://forums.phpfreaks.com/topic/122626-separate-by-commas/#findComment-633214 Share on other sites More sharing options...
The Little Guy Posted September 4, 2008 Share Posted September 4, 2008 OR $sql = "selece email from table"; $result = mysql_query($sql); while($r = mysql_fetch_assoc($result)) { $emaillist .= $r['email'] . ","; } $emaillist = trim($emaillist,","); Quote Link to comment https://forums.phpfreaks.com/topic/122626-separate-by-commas/#findComment-633343 Share on other sites More sharing options...
Ken2k7 Posted September 4, 2008 Share Posted September 4, 2008 Misspelled "select". Quote Link to comment https://forums.phpfreaks.com/topic/122626-separate-by-commas/#findComment-633352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.