...

View Full Version : Color defined equation?



sobe
05-02-2009, 10:48 PM
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.

ptmuldoon
05-02-2009, 11:13 PM
Just subtract the two numbers to see if there greater than 0. Some thing like..



$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>';
}

sobe
05-02-2009, 11:19 PM
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)

venegal
05-02-2009, 11:35 PM
Put


list($x, $y) = explode("-", $row['match_score']);

at the beginning of ptmuldoon's snippet.

sobe
05-03-2009, 05:59 AM
Exactly what I was looking for!

Thank you. Props.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum