Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Color defined equation?

    I am trying to experiment with what I can, and something I am currently stumped with, is making a scoring system.

    If say, 12 points is as high as you can go, your opponent has 8. It is displayed under a "score" row in your database, and when presented on a page it displays, 12-8.

    Simple enough. But, what I want to do, is make the "score" display as either green or red color depending on if the first number is great or less than the 2nd number. If it is greater than the second number, it would be green. If it is less than the first number, it displays as red.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    Just subtract the two numbers to see if there greater than 0. Some thing like..

    PHP Code:
    $x 12;
    $y 16;

    if(
    $x-$y >= 0)
    {
        echo 
    '<font size="3" color="green">'.$x.'-'.$y.'</font>';
    } else {
        echo 
    '<font size="3" color="red">'.$x.'-'.$y.'</font>';


  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quick addition onto that though, could I use that same method for the "score row" in the database that lists exactly, "12-8". Both numbers being in the same database input. (Pulling ".$row['match_score']." from the database would bring up 12-8)

  • #4
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Put
    PHP Code:
    list($x$y) = explode("-"$row['match_score']); 
    at the beginning of ptmuldoon's snippet.

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Exactly what I was looking for!

    Thank you. Props.


  •  

    Posting Permissions

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