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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

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.