Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 88
0 Users 5 Guests Online

Color Members Names

Nothing needs changing in mysql.

First way all php no CSS.
Or second way php with CSS.

First way.
Our Code
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$fetch = mysql_query("SELECT * FROM `members`");
while ($user = mysql_fetch_array($fetch))
{
if ($user[userlevel] == 6)
{
echo ("<font face='Verdana' size='1' color='#FF0000'>$user[username]</font>");
}
elseif ($user[userlevel] == 4)
{
echo ("<font face='Verdana' size='1' color='#0000FF'>$user[username]</font>");
}
else
{
echo ("<font face='Verdana' size='1' color='#000000'>$user[username]</font>");
}
}

This piece of code lines 1 and two grab all our information from the database.
The rest of the lines determine the userlevel of the user with simple if, elseif and else.

Have fun.
SkillMaster
Views:
2461
Rating:
Posted on Monday 25th June 2007 at 11:56 AM
ShadowMage
ShadowMage
where you have:
Code

if ($user[userlevel] == 6)
{
echo ("<font face='Verdana' color='#FF0000'>$user[username]</font><br>");
}
elseif ($user[userlevel] == 4)
{
echo ("<font face='Verdana' color='#0000FF'>$user[username]</font><br>");
}
else
{
echo ("<font face='Verdana' color='#000000'>$user[username]</font><br>");
}
}
{
echo "<a href='members.php?user=$user[username]'>$user[username]</a><br>";
}
}


Try the following:

put this before the while:
Code

function colorname($level){
$levels = array('2','4','6');
$colors = array('#000000','#0000FF','#FF0000');
return str_replace($levels, $colors, $level);
}


Then after the while starts add:
Code

$color = colorname($user[userlevel]);

Then for echoing users put:
Code

echo "<a href="members.php?user=$user[username]"><font face="Verdana" color="$color">$user[username]</font></a>";


Not sure if that will work but give it a try.
Posted on Monday 25th June 2007 at 08:05 AM
dtnet
dtnet
http://henrik.hotserv.dk/members.php

As you can see, it's listed the members twice... I don't know why.

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php 
session_start
(); //allows session 
require_once "config.php";
include(
'header.php') ; ?>
<div class="left">
<div class="divheader">Medlemmer
</div>
<?php 
if(isset($_GET['user'])){ //if there trying to view a profile 
//gets the user name and makes it safe 
$username addslashes($_GET[user]); 
//querys the db to find the username 
$getuser mysql_query("SELECT * FROM `members` WHERE `username` = '$username'"); 
//checks see if the username exists in the db  
$usernum mysql_num_rows($getuser); 
//if it don't exist  
if ($usernum == 0)  

{  
//don't exist 

echo ("Bruker ble ikke funnet");  

//if it does exist then show there profile 
}
else 

$user mysql_fetch_array($getuser); 
$user_rank change_levels($user[userlevel]); 
echo 
"<fieldset style='width: 350'> 
<b>
$user[username]'s Profil</b><br><br><br>
<img src='
$user[avatar]'></a><br>
Brukerlevel: 
$user_rank 
Email: 
$user[email]<br> 
Sted: 
$user[location]<br> 
Kjønn: 
$user[sex]<br> 
Alder: 
$user[age] 
</fieldset>"




else 

//gets all the members from the database 
$getusers mysql_query("SELECT * FROM `members` ORDER BY `id` ASC") or die(mysql_error());  
//loops their names out 
while ($user mysql_fetch_array($getusers))  

if (
$user[userlevel] == 6

echo (
"<font face='Verdana' color='#FF0000'>$user[username]</font><br>"); 

elseif (
$user[userlevel] == 4

echo (
"<font face='Verdana' color='#0000FF'>$user[username]</font><br>"); 

else 

echo (
"<font face='Verdana' color='#000000'>$user[username]</font><br>");  
}
}

echo 
"<a href='members.php?user=$user[username]'>$user[username]</a><br>";  

}
?></div>
<?php include('footer.php'); ?>
Posted on Saturday 23rd June 2007 at 01:01 AM
SkillMaster
SkillMaster
Anything you like where every you like.
Posted on Saturday 23rd June 2007 at 12:43 AM
MCP
MCP
Where does this get inserted? Like which file?
Posted on Friday 22nd June 2007 at 08:04 PM
cyruswu
cyruswu
Nice tut. I'm going to release an tut very soon. On how to add more fields from your profiles. Since, no one can see any comments.
Posted on Thursday 21st June 2007 at 09:31 PM
dtnet
dtnet
Sorry, my bad.

I was looking at the Color Members Names, but there were some errors: When I'm using method 1 the members shos up like http://henrik.hotserv.dk/members.php?user=Mads

As you can see there are something wrong since the memberlist shows up over the user profile.

When I'm using method 2 nothing happends
Posted on Thursday 21st June 2007 at 09:23 PM
SkillMaster
SkillMaster
Method 1 works or 2?
Posted on Thursday 21st June 2007 at 09:14 PM
dtnet
dtnet
Method 2 works
Posted on Thursday 21st June 2007 at 09:08 PM
dtnet
dtnet
Sorry, it doesn't works for me. I used the second method, but I'll try the first one now
Posted on Thursday 21st June 2007 at 08:45 PM
SkillMaster
SkillMaster
Post to tell me if it works?