gaza165 Posted July 3, 2009 Share Posted July 3, 2009 Hi All, Im trying to seperate users online by a comma, however when it the last user i obviously dont need the comma there. So fair I have got Anonymous, Anonymous, Garry, <?php include("dbconnect.php"); $guests = mysql_query("SELECT * FROM active_users WHERE TIMESTAMPDIFF(MINUTE,last_active, CURRENT_TIMESTAMP()) < 2 "); $num_of_guests = mysql_num_rows($guests); if($num_of_guests == 1) { $response = "<h4 class='active'>There is ".$num_of_guests." user online</h4>"; } elseif($num_of_guests > 1) { $response = "<h4 class='active'>There are ".$num_of_guests." users online</h4>"; $comma = ", "; } elseif($num_of_guests == 0) { $response = "<h4 class='active'>There are ".$num_of_guests." users online</h4>"; } echo $response; while($row = mysql_fetch_array($guests)) { $nick = $row['alias_name']; ?> <span class="activenick"><? echo $nick ?>,</span> <?}?> Link to comment https://forums.phpfreaks.com/topic/164643-solved-need-help-with-simple-problem/ Share on other sites More sharing options...
Adam Posted July 3, 2009 Share Posted July 3, 2009 You could do it like this: while($row = mysql_fetch_array($guests)) { $user_list .= '<span class="activenick">' . $row['alias_name'] . '</span>,'; } print rtrim($user_list, ','); Link to comment https://forums.phpfreaks.com/topic/164643-solved-need-help-with-simple-problem/#findComment-868274 Share on other sites More sharing options...
SetToLoki Posted July 3, 2009 Share Posted July 3, 2009 $nick = array (); while($row = mysql_fetch_array($guests)) { $nick[] = $row['alias_name']; } echo implode(",", $nick); Link to comment https://forums.phpfreaks.com/topic/164643-solved-need-help-with-simple-problem/#findComment-868275 Share on other sites More sharing options...
gaza165 Posted July 3, 2009 Author Share Posted July 3, 2009 Brilliant!!! Thanks guys that was a great help!! Link to comment https://forums.phpfreaks.com/topic/164643-solved-need-help-with-simple-problem/#findComment-868277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.