Mr Nick Posted July 12, 2010 Share Posted July 12, 2010 So far my simple code works properly. It outputs: "user1, user2, user3, " However I'd like it to output: "user1, user2 and user3." while($user_fetch = $db->fetch_assoc($chars_fetch)){ echo $user_fetch['username'] . ', '; } Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 12, 2010 Share Posted July 12, 2010 $userList = array(); while($user_fetch = $db->fetch_assoc($chars_fetch)) { $userList[] = $user_fetch['username']; } echo implode(',', $userList); Quote Link to comment Share on other sites More sharing options...
Mr Nick Posted July 12, 2010 Author Share Posted July 12, 2010 That's not exactly what I want to do . It's already outputting to "user1, user2, user3, " so the commas are already displaying. Just for the last part ("user3, "), I'd want the command removed and replaced with a period. EDIT: The actual variable ( $user_fetch['username'] ) is the actual usernames. There is no comma in this. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 12, 2010 Share Posted July 12, 2010 That's not exactly what I want to do . It's already outputting to "user1, user2, user3, " so the commas are already displaying. Just for the last part ("user3, "), I'd want the command removed and replaced with a period. EDIT: The actual variable ( $user_fetch['username'] ) is the actual usernames. There is no comma in this. The way mjdamato has shown is the fairly standard way of doing this. To add a period: echo implode(',', $userList) . '.'; It's going to be a big hassle echoing each as you have shown. Quote Link to comment Share on other sites More sharing options...
Mr Nick Posted July 12, 2010 Author Share Posted July 12, 2010 Awesome! Thanks man. Quote Link to comment 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.