gurpreet Posted May 27, 2010 Share Posted May 27, 2010 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 Quote Link to comment Share on other sites More sharing options...
sniko Posted May 27, 2010 Share Posted May 27, 2010 Firstly, quote the variables, for example $r['username'] = "<font color = red>$r['username']</font>"; And second, i don't understand the issue Quote Link to comment Share on other sites More sharing options...
gurpreet Posted May 27, 2010 Author Share Posted May 27, 2010 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? Quote Link to comment Share on other sites More sharing options...
Guest Posted May 27, 2010 Share Posted May 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
CJ - Twitch Posted May 27, 2010 Share Posted May 27, 2010 You do understand that BBCode is PHP. Don't you? :huh: Quote Link to comment Share on other sites More sharing options...
CJ - Twitch Posted May 27, 2010 Share Posted May 27, 2010 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. :) Quote Link to comment Share on other sites More sharing options...
gurpreet Posted May 27, 2010 Author Share Posted May 27, 2010 You do understand that BBCode is PHP. Don't you? :huh: It is? Well then shouldn't it work perfectly with the coding methods of PHP? Doesn't seem to work... Quote Link to comment Share on other sites More sharing options...
Jordan Palmer Posted May 28, 2010 Share Posted May 28, 2010 I do something along the lines off CrazyT's way. @OP; I'll help on MSN If you need it :) Quote Link to comment Share on other sites More sharing options...
Guest Posted May 30, 2010 Share Posted May 30, 2010 You do understand that BBCode is PHP. Don't you? :huh: In fact your wrong, BBCode is html. Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted May 30, 2010 Share Posted May 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
Guest Posted May 30, 2010 Share Posted May 30, 2010 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 :) Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted May 30, 2010 Share Posted May 30, 2010 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); Quote Link to comment Share on other sites More sharing options...
gurpreet Posted May 30, 2010 Author Share Posted May 30, 2010 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] Quote Link to comment Share on other sites More sharing options...
Brad Posted May 30, 2010 Share Posted May 30, 2010 You can just edit the user name on ur admin panel to give a color but when u edit it on pref it dont work so it easy way to do that Quote Link to comment Share on other sites More sharing options...
gurpreet Posted May 30, 2010 Author Share Posted May 30, 2010 You can just edit the user name on ur admin panel to give a color but when u edit it on pref it dont work so it easy way to do that Read through the post...I've tried that, but I have BBcoded forums so it doesn't work out properly. Quote Link to comment Share on other sites More sharing options...
Brad Posted May 30, 2010 Share Posted May 30, 2010 Ok i do that sometimes works. Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted May 30, 2010 Share Posted May 30, 2010 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. Quote Link to comment Share on other sites More sharing options...
Jordan Palmer Posted May 30, 2010 Share Posted May 30, 2010 <font> is Deprecated Not being an asshole, but if you're gunna do something do it right ;D Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted May 30, 2010 Share Posted May 30, 2010 $return_data = (array_key_exists($user_level, $staff_colours)) ? '<span style="color: '.$staff_colours[$user_level].';">'.$username.'</span>' : $username ; For Jordan ... Alan is deprecated but we still love him lol Quote Link to comment Share on other sites More sharing options...
Jordan Palmer Posted May 30, 2010 Share Posted May 30, 2010 LOL! :P Quote Link to comment Share on other sites More sharing options...
gurpreet Posted May 30, 2010 Author Share Posted May 30, 2010 Same thing comes up. Maybe I'm putting in the wrong code? I put the following in my header: $ir['username'] = ".username($ir{['username']})."; Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted May 30, 2010 Share Posted May 30, 2010 $ir['username'] = username($ir['user_level'],$ir['username']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.