www.webdeveloper.com
Results 1 to 3 of 3

Thread: changing colors

  1. #1
    Join Date
    Jun 2006
    Posts
    10

    changing colors

    Hi all.

    This has to be the ulitmate noob question. I have a little php script that I have been trying to modify but not luck.

    From the beginning. I have a game server on my linux box and a webserver. On the webserver is a page where I want to display number of players on the server. So in theory it should work like this :

    if pleyers > 0 then
    print statment in white 1 ( if there is someone on the server )
    else
    print statment in gray 2 ( if the server is empty )

    Here is the code :

    PHP Code:
    if ($server->server_num_players )
    {
        echo 
    '<font color="#FFFFFF">'."Current Map: ".$server->server_map."<br>";
        echo 
    '<font color="#FFFFFF">'."Players: ".$server->server_num_players;
        echo 
    '<font color="#FFFFFF">'." of ".$server->server_num_players_max;
        }
        else
        {
        echo 
    '<font color="#808080">'."Current Map: ".$server->server_map."<br>";
        echo 
    '<font color="#808080">'."Players: ".$server->server_num_players;
        echo 
    '<font color="#808080">'." of ".$server->server_num_players_max;

    The number of players are displayed correctly but the font color is always gray no matter if the server is empty or not.

    Thanks for your time
    Last edited by stebbi67; 08-04-2006 at 11:35 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,617
    Worked OK for me. However, I'd recommend getting rid of the deprecated <font> tags, plus compacting things a bit:
    PHP Code:
    $color = ($server->server_num_players 0) ? "#FFFFFF" "#808080";
    echo 
    "<span style='color: $color;'>Current Map: ".$server->server_map."<br>";
    echo 
    "Players: ".$server->server_num_players." of ";
    echo 
    $server->server_num_players_max."</span>"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2006
    Posts
    10
    Ok, thanks. My code does not work for me, but yours does

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles