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). 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> -'); 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 ?> 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++; } ?> 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> Link to comment https://forums.phpfreaks.com/topic/87434-user-online-seperate/#findComment-447315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.