PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Apr 07, 2006 6:25 pm
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
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Apr 07, 2006 6:48 pm
English?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Apr 07, 2006 6:54 pm
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;
}
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Apr 07, 2006 6:57 pm
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
Green would be Moderators
White would be Users
Red would be Admin
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Apr 07, 2006 7:11 pm
im not really sure on scripting that into my script
really
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Apr 07, 2006 7:13 pm
Smackie wrote: im not really sure on scripting that into my script
really
can you reword this please, I don't quite follow..
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Apr 07, 2006 7:17 pm
sorry just been a busy day lol.... umm how can i strip my script down and add that script in there?
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Sat Apr 08, 2006 8:32 am
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>';
}
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Apr 08, 2006 8:35 am
move the function declaration to just below the require?