Jump to content
MakeWebGames

Recommended Posts

Posted

heres what i got 

 }
        if ($r['donatordays'])
        {
            $r['username'] = "<font color=red>{$r['username']}</font>";
            $d =
                    "<img src='donator.gif' alt='Donator: {$r['donatordays']} Days Left' title='Donator: {$r['donatordays']} Days Left' />";
        }
        else if ($r['user_level'] == 2)
        {
            $r['username'] = "<font color=blue>{$r['username']}</font>";
            $d =
        }
        if ($r['laston'] >= time() - 15 * 60)
        {
            $on = "<font color=green><b>Online</b></font>";
        }
        else
        {
            $on = "<font color=red><b>Offline</b></font>";
        }

 

Posted (edited)

How about creating a function?

function username($userid) {
        global $db, $ir;
        if(!$userid) {
            return 'N/A';
        }
        $colours = array(
            1 => 'brown',
            2 => 'gold',
            3 => 'blue'
        );
        $select = mysql_query("SELECT `username`, `user_level` FROM `users` WHERE `userid` = " . $userid);
        if(!$mysql_num_rows($select)) {
            return 'N/A';
        }
        $user = mysql_fetch_array($select);
        $ret = '';
        if($user['user_level'] > 1) {
            $ret = "<a href='viewuser.php?u=".$userid."' style='color:".$colours[$user['user_level']].";'>".$user['username']."</a>";
        } else if(!$user['user_level']) {
            $ret = "<a href='viewuser.php?u=".$userid."' style='color:brown;' title='NPC'>".$user['username']."</a>";
        } 
        return $ret;
    }
	

 

Add that to global functions and when you want to a username to display use e.g. -

 <?php echo username($r['userid']); ?>

You can still add on to this to show donator users and etc.

Edited by Shades
Posted

Reason for your staff colours not overriding donator is because you've added them after the donator colouring condition.
Flip 'em round (see example below)

if ($r['user_level'] == 2) {
    $r['username'] = "<font color=blue>{$r['username']}</font>";
    $d = '';
} elseif ($r['donatordays']) {
    $r['username'] = "<font color=red>{$r['username']}</font>";
    $d = "<img src='donator.gif' alt='Donator: {$r['donatordays']} Days Left' title='Donator: {$r['donatordays']} Days Left' />";
}


If you don't mind your staff members also having the donator icon (if applicable), you can set $d between your colour conditions and username output

<?php 
$color = null;
if($r['user_level'] == 2) {
    $color = 'blue';
} elseif($r['donatordays'] > 0) {
    $color = 'red';
}
if($r['donatordays'] > 0) {
    $titleAlt = 'Donator: '.$r['donatordays'].' Day'.($r['donatordays'] == 1 ? '' : 's').' Left';
    $d = ' <img src="donator.gif" title="'.$titleAlt.'" alt="'.$titleAlt.'" />';
} else {
    $d = '';
}
if($color !== null) {
   $r['username'] = '<span style="color:'.$color.';">'.$r['username'].'</span>';
}

// Output
echo $r['username'],$d;


That being said, I would recommend throwing this logic into a function seeing as there are 120 instances of a username being echoed out somewhere - that's a lot of places to update in order to unify your changes.
@Shades's function would get you off the ground. Tweak to your liking and implement across the board!

  • 1 year later...
Posted (edited)

I got a mod called VIP Passes. 

 

What exactly is a Donator Mod though? Sounds like something I might like to create. B/:)

Edited by Sim

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...