doddsey_65 Posted October 12, 2010 Share Posted October 12, 2010 i have a users online section and i am using an aray and implode so the comma is displayed on every username but the last, but it displays the same usernames several times. This could be due to the switch i am using to define user group. Heres the code: $online_query = $db->query("SELECT user_id, user_group, user_username FROM ".DB_PREFIX."sessions"); while ($online_info = mysql_fetch_object($online_query)) { switch($online_info->user_group) { case 1: $userClass = 'admin'; break; case 2: $userClass = 'mod'; break; case 3: case 0: default: $userClass = 'user'; break; } $users2[] = "<span class=\"{$userClass}\">{$online_info->user_username}</span>"; echo '<p>' . implode(', ', $users2) . '</p>'; } is there something i am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/215670-array-problems/ Share on other sites More sharing options...
kenrbnsn Posted October 12, 2010 Share Posted October 12, 2010 Where is the variable $users2 getting populated? Ken Quote Link to comment https://forums.phpfreaks.com/topic/215670-array-problems/#findComment-1121344 Share on other sites More sharing options...
doddsey_65 Posted October 12, 2010 Author Share Posted October 12, 2010 $users2 = array(); Quote Link to comment https://forums.phpfreaks.com/topic/215670-array-problems/#findComment-1121356 Share on other sites More sharing options...
Pikachu2000 Posted October 12, 2010 Share Posted October 12, 2010 You have your echo inside the while() loop. Every time a value is added to the array, the updated array is imploded and the string is echoed. Quote Link to comment https://forums.phpfreaks.com/topic/215670-array-problems/#findComment-1121357 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.