Page 1 of 1

Colored names for users online

Posted: Fri Apr 07, 2006 6:25 pm
by Smackie
I have this script and i was wondering if there was a way i could get like say Smackie (me as i am an admin on the site) was on and several others but i only wanted Smackie like green and leave the others white how would i do that? i mean something like what the forum as for admin its like red and stuff like that..


here is the online script..

Code: Select all

<?php 

require 'db.php'; 

mysql_query("UPDATE users SET online_time=now() WHERE user_name='".$_SESSION['user_name']."'"); 

$members_online = mysql_query("SELECT * FROM users WHERE UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(online_time) <=300"); 
if(mysql_num_rows($members_online) == 0) { 

     echo "<font class=\"txt\">No users online.</font>"; 

} else { 


     while($members_onlinearray = mysql_fetch_array($members_online)){ 

         echo "<font class=\"txt\">";
         echo '<a class="txt" href="../index.php?pages=members_profile&user_name='.$members_onlinearray['user_name'] .'">';
         echo $members_onlinearray['user_name']; 
         echo '</a>';
         echo "</font><br>"; 
    } 
} 

?>
thank you
Smackie

Posted: Fri Apr 07, 2006 6:48 pm
by Luke
English?

Posted: Fri Apr 07, 2006 6:54 pm
by John Cartwright
I usually do something like this (simplified)

Code: Select all

function format_name($username, $permission) {
   return '<span class="user'.$permission.'">'.$username.'</span>';
}   

echo format_name($members_onlinearray['user_name'], $members_onlinearray['permission']);
and have in your stylesheet the colors for each different user permission

Code: Select all

span.user1 {
   color: #DDD;
}

span.user2 {
   color #CCC;
}

Posted: Fri Apr 07, 2006 6:57 pm
by Smackie
that is english... i just want like a list of users or something that will have like different font colors.. i want it to look like this when users online

Image


Green would be Moderators
White would be Users
Red would be Admin

Posted: Fri Apr 07, 2006 7:11 pm
by Smackie
:? im not really sure on scripting that into my script :? really :?

Posted: Fri Apr 07, 2006 7:13 pm
by John Cartwright
Smackie wrote::? im not really sure on scripting that into my script :? really :?
can you reword this please, I don't quite follow..

Posted: Fri Apr 07, 2006 7:17 pm
by Smackie
sorry just been a busy day lol.... umm how can i strip my script down and add that script in there?

Posted: Sat Apr 08, 2006 8:32 am
by Smackie
ok i figured it out last night but now a problem when someone else is logged in and i try login in i get this error
Fatal error: Cannot redeclare format_name() (previously declared in /home/maplarz/public_html/users_online.php:16) in /home/maplarz/public_html/users_online.php on line 16

Code: Select all

<?php 

require 'db.php'; 

mysql_query("UPDATE users SET online_time=now() WHERE user_name='".$_SESSION['user_name']."'"); 

$members_online = mysql_query("SELECT * FROM users WHERE UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(online_time) <=300"); 
if(mysql_num_rows($members_online) == 0) { 

     echo "<font class=\"txt\">No users online.</font>"; 

} else { 

     while($members_onlinearray = mysql_fetch_array($members_online)){ 

function format_name($username, $user_level) {
   return '<span class="user'.$user_level.'">'.$username.'</span>';
}   
 echo '<a class="txt" href="../index.php?pages=members_profile&user_name='.$members_onlinearray['user_name'] .'"><b>';
echo format_name($members_onlinearray['user_name'], $members_onlinearray['user_level']);
echo '</b></a>';
  }
}

?>

Posted: Sat Apr 08, 2006 8:35 am
by feyd
move the function declaration to just below the require?