runnerjp Posted October 28, 2008 Share Posted October 28, 2008 im shoing a list of users print "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>,"; and i feel it would look nicer if the comma was not on the end of the last one... i know i could use an if statement to show just a name if there is just one user but what if there is more... how would i prevent the comma been shown? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 28, 2008 Share Posted October 28, 2008 i assume this is in some loop... <?php $users = array(); foreach(...loop stuff here...){ $users[] = "<a href='$getusersonline3[user]'>$getusersonline3[user]</a>"; } print implode(',',$users); } ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted October 28, 2008 Author Share Posted October 28, 2008 nope no loop... full code is as shows.. <?php $getusersonline="SELECT user_id,user FROM useronline WHERE file = 'http://www.runningprofiles.com/members/index.php?page=forum&forum=$forum' AND timestamp > " . (time() - 900) ; //grab from sql users on in last 15 minutes $getusersonline2=mysql_query($getusersonline) or die("Could not get users"); $num=mysql_num_rows($getusersonline2); echo "<b>There " . ($num != 1 ? "are" : "is") . " $num user" . ($num != 1 ? "s" : "") . " currently viewing the $forum board: </B>"; while($getusersonline3=mysql_fetch_array($getusersonline2)) { print "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>,"; } ?> would there be a better way of doing this? also would i just add print implode(',',$users); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 28, 2008 Share Posted October 28, 2008 As rhodesa said, just replace: <?php while($getusersonline3=mysql_fetch_array($getusersonline2)) { print "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>,"; } ?> with <?php $tmp = array(); while($getusersonline3=mysql_fetch_array($getusersonline2)) { $tmp[] = "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>"; } echo implode(',',$tmp); ?> Ken Quote Link to comment Share on other sites More sharing options...
kmaid Posted October 28, 2008 Share Posted October 28, 2008 Yo Jaret guess who! Just load all the userids into an array and then use the imlpode function. while($getusersonline3=mysql_fetch_array($getusersonline2)) { $UserIDs = $getusersonline3[user]; } echo implode(',',$UserIDs ); edit Haha, I was beaten twice and missed the []s off UserIDs ^^; 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.