php - Commas after a loop -


i want add comma every username except last one. example: user1, user2, user3 how do this? here code:

$user_online_sql = $db->query("select distinct account_id online account_id != '-1';"); $users = ''; while ($user_online_row = mysql_fetch_array($user_online_sql)) { $users .= $user->name($user_online_row['account_id']) . ' '; } 

i tried implode function outputted blank result, here code implode function:

 $user_online_sql = $db->query("select distinct account_id online account_id != '-1';"); $users = ''; while ($user_online_row = mysql_fetch_array($user_online_sql)) { $users .= implode(', ',$user->name($user_online_row['account_id'])) . ' '; }  

you right using implode, you're going wrong.

$users = []; // or array() in php 5.3 , older while($user_online_row = mysql_fetch_assoc($user_online_sql)) {     $users[] = $user->name($user_online_row['account_id']); } $users = implode(", ",$users); echo $users; 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -