birdbrain24 Posted January 23, 2008 Share Posted January 23, 2008 How can i sperate the users in my code without there being a - left at the end ? <html> <head> <title>RACE</title> </head> <body> <?php # Common functions! session_start(); include('functions.php'); pageinfo('January 23 2008', 'January 23 2008'); connect(); sessioncheck(); lastaction(); $username=$_SESSION['username']; $timenow = time(); $select = mysql_query("SELECT * FROM users WHERE lastaction > '$timenow' ORDER by username ASC"); while($grab = mysql_fetch_array($select)){ if($users['userlevel'] == 'Admin'){ echo('<a href=\'profile.php?user='.$users['username'].'\'><b><font color=red>'.$users['username'].'</font></b></a> -"'); } elseif($users['userlevel'] == 'Head'){ echo('<a href=\'profile.php?user='.$users['username'].'\'><b><font color=orange>'.$users['username'].'</font></b></a> -"'); } elseif($users['userlevel'] == 'Mod'){ echo('<a href=\'profile.php?user='.$users['username'].'\'><b><font color=yellow>'.$users['username'].'</font></b></a> -"'); }else{ echo('<a href=\'profile.php?user='.$users['username'].'\'><b><font color=lightblue>'.$users['username'].'</font></b></a> -"'); } } ?> </body> </html> I would like to seperate the users with a -! Like it is here on the forums just using a -(dash) instide of using a ,(comma). Quote Link to comment https://forums.phpfreaks.com/topic/87434-user-online-seperate/ Share on other sites More sharing options...
rbrown Posted January 23, 2008 Share Posted January 23, 2008 Do a count of the users returned. Loop through the display When the count = count then use same line without the - on the end. Also use double quotes in your html. 1) makes it easier to read. 2) less chance of forgetting to escape a single quote. 3) is the correct way to write code. echo('<a href="profile.php?user='.$users['username'].'"><b><font color="orange">'.$users['username'].'</font></b></a> -'); Quote Link to comment https://forums.phpfreaks.com/topic/87434-user-online-seperate/#findComment-447201 Share on other sites More sharing options...
The Little Guy Posted January 23, 2008 Share Posted January 23, 2008 or <?php $user = 'superboy-'; echo rtrim($user, '-'); // Prints: superboy ?> Quote Link to comment https://forums.phpfreaks.com/topic/87434-user-online-seperate/#findComment-447205 Share on other sites More sharing options...
The Little Guy Posted January 23, 2008 Share Posted January 23, 2008 More: <?php $aCount = count($myArray); $i = 0; while($row = mysql_fetch_array($sql)){ if($aCount == $i){ echo rtrim($user, '-'); }else{ echo $user; } $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87434-user-online-seperate/#findComment-447208 Share on other sites More sharing options...
birdbrain24 Posted January 23, 2008 Author Share Posted January 23, 2008 More: <?php $aCount = count($myArray); $i = 0; while($row = mysql_fetch_array($sql)){ if($aCount == $i){ echo rtrim($user, '-'); }else{ echo $user; } $i++; } ?> I can't seem to get this to work! So i tried thid myself and i thought it would work but it doesn't <html> <head> <title>RACE</title> </head> <body> <?php # Common functions! session_start(); include('functions.php'); pageinfo('January 23 2008', 'January 23 2008'); connect(); sessioncheck(); lastaction(); $username=$_SESSION['username']; $timenow = time(); $users_query = mysql_query("SELECT * FROM users WHERE lastaction > '$timenow' ORDER by username ASC"); $count = mysql_num_rows($users_query); $i = 0; while($users = mysql_fetch_array($users_query)){ $i = 0; if($count > $i){ echo($users['username'].' - '); $i++; } elseif($count == $i){ echo($users['username']); } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/87434-user-online-seperate/#findComment-447315 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.