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? 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 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(); 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. Link to comment https://forums.phpfreaks.com/topic/215670-array-problems/#findComment-1121357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.