How to make a certain username a certain colour with PHP [HELP]

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
Hey,

I have a users online page and it displays all the users online. I'm wanting to make my username bold and red so it stands out since im the owner (my username is Josh) but I can't figure out how to do it. Heres my code:

Code:
<div class="habblet-container ">         
<div class="cbb clearfix red ">  
<h2 class="title">Online Users</h2> 
<div align="left">
<div class="box-content">
 
<?php
 
require_once 'global.php';
 
$getUsers = dbquery("SELECT id,username,motto,look,online, last_online FROM users WHERE online = '1' ORDER BY id ASC");
$getMembers = dbquery("SELECT username FROM users WHERE rank = '8' ORDER BY id ASC");
 
 
if (mysql_num_rows($getUsers) > 0)
{
echo '<ul style="margin: 0; color:#000000">';
 
while ($u = mysql_fetch_assoc($getUsers))
{
echo $users->formatUsername($u['id']);echo ', ';
 
}
 
echo '</ul>';
}
else
{
echo '<br /><br /><i>There are currently no users online.</i>';
}
 
?> 
 
    </div> 
</div> 
    </div></div>

An ideas?
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
This looks a little bit messy, but don't know how to explain it. Maybe you can use something like this to create "ifs" when someone is a special rank.

PHP:
if ($row['rank'] == "4") {
$color = "color_name";
}

And add something like this in your style.css:
PHP:
.name_pink{color:#ff49b;}
.name_black{color:black; font-weight:bold;}
.name_green{color:#0db600; font-weight:bold;}
.name_purple{color:#7501b1;}
.name_orange{color:#ff921e;}
.name_red{color:#ff0000;}
.name_gray{color:#CCCCCC;}

I'm sure there misses some code, but it's a start.
 

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
This looks a little bit messy, but don't know how to explain it. Maybe you can use something like this to create "ifs" when someone is a special rank.

PHP:
if ($row['rank'] == "4") {
$color = "color_name";
}

And add something like this in your style.css:
PHP:
.name_pink{color:#ff49b;}
.name_black{color:black; font-weight:bold;}
.name_green{color:#0db600; font-weight:bold;}
.name_purple{color:#7501b1;}
.name_orange{color:#ff921e;}
.name_red{color:#ff0000;}
.name_gray{color:#CCCCCC;}

I'm sure there misses some code, but it's a start.

What do I define the color variable as? eg. $color = 'lalal';

Also, I got this from my staff page:

PHP:
if($u['username'] == 'Subway')
{
$u['username'] = 'Owner';
}

But it didn't work :l
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
What do I define the color variable as? eg. $color = 'lalal';

Also, I got this from my staff page:

PHP:
if($u['username'] == 'Subway')
{
$u['username'] = 'Owner';
}

But it didn't work :l

Because it isn't a valid PHP code. I think you need something like this, depens on the variables you use.

PHP:
$u['username'] = 'Owner';

=

PHP:
$rank= "Owner";
 

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
$users->formatUsername($u['id'])

Can you show me the function formatUsername from your users class?

Sure:
PHP:
 function formatUsername($id, $link = true, $styles = true)
{
$datas = dbquery("SELECT id,rank,username FROM users WHERE id = '" . $id . "' LIMIT 1");
 
if (mysql_num_rows($datas) == 0)
{
return '<s>Unknown User</s>';
}
 
$data = mysql_fetch_assoc($datas);
 
$prefix = '';
$name = $data['username'];
$suffix = '';
 
if ($link)
{
$prefix .= '<a href="/user/' . clean($data['username']) . '">';
$suffix .= '</a>';
}
 
if ($styles)
{
$rank = $this->getRank($id);
 
}
 
return clean($prefix . $name . $suffix, true);
}
 

leenster

Member
Dec 26, 2011
77
19
A simple way of doing it.
PHP:
if ($link)
{
 
 
if(clean($data['username'])== 'JoshuaLuke') $class = ' class="someCSSclass"'; else $class = '';
 
$prefix .= '<a href="/user/' . clean($data['username']) . '" ' .$class. '>';
$suffix .= '</a>';
}

then in your style sheet create the someCSSclass

Not tested but should work...


A better way would be to use your ID..
something like
if(clean($data['id'])== '1') $class = 'class="someCSSclass"'; else $class = '';
 

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
A simple way of doing it.
PHP:
if ($link)
{
 
 
if(clean($data['username'])== 'JoshuaLuke') $class = 'class="someCSSclass"'; else $class = '';
 
$prefix .= '<a href="/user/' . clean($data['username']) . '" ' .$class. '>';
$suffix .= '</a>';
}

then in your style sheet create the someCSSclass

Not tested but should work...

Where bouts do I put that? :L
 

leenster

Member
Dec 26, 2011
77
19
try it without the clean()...
Code:
if ($link)
{
    if($data['username']== 'JoshuaLuke') $class = 'class="someCSSclass"'; else $class = '';
 
    $prefix .= '<a href="/user/' . clean($data['username']) . '" ' .$class. '>';
    $suffix .= '</a>';
}



make sure to replace your
if ($link)
{$prefix .= '<a href="/user/' . clean($data['username']) . '">';$suffix .= '</a>';
}

with the one i gave you..


from what i can see it should work...
 

Users who are viewing this thread

Top