Jump to content
MakeWebGames

Going about staff colours


gurpreet

Recommended Posts

Hey everyone, I was wondering how I would go about adding colours to staff names, in general through the DB (Changing the name) or header or something...My dilemma is that I have BBCode forums (MTGs) and the rest is PHP, so if I edit someone's name via the DB they'll be fine in-game, but on the forums it will show: <font color=blue>Gurpz</font>, and if they have a few colours it will be even longer. Is there an easy way to do this, or would i have to go through every page and add an if statement to check if they're staff, then it'll change the username to coloured like this:

 

if($r['user_level'] > 1)
{
if($r['user_level'] ==  2)
{
$r['username'] = <font color = blue>$r['username']</font>;
}
else if($r['user_level'] == 3)
{
$r['username'] = <font color = red>$r['username']</font>;
}
}

and it'll keep going until all user levels are covered. Sorry for the long post, just want to be crystal clear on the issue. Any help will be appreciated

Link to comment
Share on other sites

Firstly, quote the variables, for example

 

$r['username'] = "<font color = red>$r['username']</font>";

 

And second, i don't understand the issue

Ok basically, my game overall is in PHP, but the forums are in BBCode. As you know, the BBCode and PHP have different coding methods, <font color> and . By doing one method, the other method will be screwed up. E.G. php way, the <font color=blue> will show up instead of a blue name on the forums, and with that will show as it is in the whole game. Would it be wise to add a BBCode parser (or the thing where all of BBCodes are) to the header?

Link to comment
Share on other sites

Use a function pass user_level & username to the function...

Example..

function userColor ( $level = 0, $name )
{
$colors = array
(
	1 => '111',
	2 => '222',
	3 => '333'
);
$color = array_key_exists($level, $colors) ? $colors[$level] : null; //default
return is_null($color) ? $name : '<span style="color: #'. $color .';">'. $name .'</span>';
}
#Useage:
echo userColor ($r['user_level'], $r['username']);

Note: This hasn't been tested. - There are probably better ways than I've posted.

Link to comment
Share on other sites

Use a function pass user_level & username to the function...

Example..

function userColor ( $level = 0, $name )
{
$colors = array
(
	1 => '111',
	2 => '222',
	3 => '333'
);
$color = array_key_exists($level, $colors) ? $colors[$level] : null; //default
return is_null($color) ? $name : '<span style="color: #'. $color .';">'. $name .'</span>';
}
#Useage:
echo userColor ($r['user_level'], $r['username']);

Note: This hasn't been tested. - There are probably better ways than I've posted.

8o Very efficient! Thanks for this. :)

Link to comment
Share on other sites

  function username($ident) {
#   function username($user_level, $username) {
$staff_colours = array(
	'1' => '#fff', 
	'2' => 'CC0', 
	'3' => '#FFC', 
	'5' => '006'
);
   foreach ($staff_colours as $c_key => $c_value) {
	$return_data = ( $ident['user_level'] == $c_key ) ? '<font color='.$c_value.'>'.$ident['username'].'</font>' : $ident['username'] ;
#	$return_data = ( $user_level == $c_key ) ? '<font color='.$c_value.'>'.$username.'</font>' : $username ;
   }
return $return_data;
 }
  echo username($ir);
# echo username($ir['user_level'],$ir['username']);

Just a quick knock up lol

Link to comment
Share on other sites

  function username($ident) {
#   function username($user_level, $username) {
$staff_colours = array(
	'1' => '#fff', 
	'2' => 'CC0', 
	'3' => '#FFC', 
	'5' => '006'
);
   foreach ($staff_colours as $c_key => $c_value) {
	$return_data = ( $ident['user_level'] == $c_key ) ? '<font color='.$c_value.'>'.$ident['username'].'</font>' : $ident['username'] ;
#	$return_data = ( $user_level == $c_key ) ? '<font color='.$c_value.'>'.$username.'</font>' : $username ;
   }
return $return_data;
 }
  echo username($ir);
# echo username($ir['user_level'],$ir['username']);

Just a quick knock up lol

Bit over the top ain't it lol - No need to use a foreach loop :)

Link to comment
Share on other sites

  function username($ident) {
   $staff_colours = array(
       1 => '#fff', 
       2 => '#CC0', 
       3 => '#FFC', 
       5 => '#006'
   );
	$return_data = (array_key_exists($ident['user_level'], $staff_colours)) ? '<font color='.$staff_colours[$ident['user_level']].'>'.$ident['username'].'</font>' : $ident['username'] ;
   return $return_data;
 }
  echo username($ir);
Link to comment
Share on other sites

  function username($ident) {
   $staff_colours = array(
       1 => '#fff', 
       2 => '#CC0', 
       3 => '#FFC', 
       5 => '#006'
   );
	$return_data = (array_key_exists($ident['user_level'], $staff_colours)) ? '<font color='.$staff_colours[$ident['user_level']].'>'.$ident['username'].'</font>' : $ident['username'] ;
   return $return_data;
 }
  echo username($ir);

 

I used this function, but it says the following instead of a coloured username:

Name:.username(Array{['username']}. [1]

Link to comment
Share on other sites

  function username($user_level,$username) {
   $staff_colours = array(
       1 => '#fff', 
       2 => '#CC0', 
       3 => '#FFC', 
       5 => '#006'
   );
       $return_data = (array_key_exists($user_level, $staff_colours)) ? '<font color='.$staff_colours[$user_level].'>'.$username.'</font>' : $username ;
   return $return_data;
 }
  echo username($ir['user_level'],$ir['username']);

Sorry lol my mistake this should work.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...