Jump to content

Changing cell color based on value?


patsman77

Recommended Posts

Hello All,

 

I am new to this PHP stuff, but am looking for a little help. I am writing a script for a football league I am in. You pick the NFL winners each week. Now I am working on a table, that lists the player who made selection, then have it have a "green" cell if the selection is correct, or a "red" cell if the selection is wrong.

 

This is what I have so far:

 

// Get all the data from the "example" table
$result3 = mysql_query("SELECT * FROM picksheet WHERE week='1'") 
or die(mysql_error());  
echo "<table border='1'<td class='v8'>" ;
echo "<tr><th>PoolMeister</th> <th>Game01</th><th>Game02</th> <th>Game03</th> <th>Game04</th> <th>Game05</th> <th>Game06</th> <th>Game07</th> <th>Game08</th> <th>Game09</th> <th>Game10</th> <th>Game11</th> <th>Game12</th> <th>Game13</th> <th>Game14</th> <th>Game15</th> <th>Game16</th> <th>survivor</th> <th>margin</th> <th>Tiebreaker</th><th> Total Wins</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result3 )) {
        // Print out the contents of each row into a table
       







        echo "<tr><td class='v8'>";
        echo $row['user_name'];
        
//Game 1       
        if($row['Game01']=='$Game1Winner') 
        { 
        print '<TH bgcolor="green">';
        } 
    elseif ($row['Game01'] <>'$Game1Winner')
        { 
        print '<TH bgcolor="red">';
        } 
        echo $row['Game01'];
//Game 2        
        if($row['Game02']=='$Game2Winner') 
        { 
        print '<TH bgcolor="green">';
        } 
    elseif ($row['Game02'] <>'$Game2Winner')
        { 
        print '<TH bgcolor="red">';
        } 
        
        echo $row['Game02'];

 

I have the table coming up correctly, the values are correct, but the cells all come up RED, even if the selection is correct.

 

Can onyone lead me in the right direction here?

 

Any help would be greatly appreciated!!

 

Patsman77

 

If you need to see more of the code, just let me know, but I think this covers it...

Link to comment
https://forums.phpfreaks.com/topic/78865-changing-cell-color-based-on-value/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.