473,378 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Changing cell color based on value?

Hello All,

I have been working on a little script, I am at a slight problem and was hoping for a little assistance.

I am trying to change the color of a cell in my table based on a value change:

It is a "Standings" page, where If a team has been noted as a "Winner", the cell be green, or if the team is a "Loser", then the cell color be red.

This is AMERICAN FOOTBALL...hehe

I have it registering the correct winner if a team wins, and a counter to total the wins....now I want it to output in a table to reflect it by color.

Here is what I have:

[PHP]// Get all the data from the "example" table
$result = 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( $result )) {
// Print out the contents of each row into a table

{

echo "<tr><td class='v8'>";
echo $row['user_name'];


echo "</td><td class='v8'>";
echo $row['Game01'];
if('$Game01'=='$Game1Winner')
{
print '<TH bgcolor="green">\n';
}
else
{
print '<TH bgcolor="red">\n';
}
echo "</td><td class='v8'>";
echo $row['Game02'];
echo "</td><td class='v8'>";
echo $row['Game03'];
echo "</td><td class='v8'>";
echo $row['Game04'];
echo "</td><td class='v8'>";
echo $row['Game05'];
echo "</td><td class='v8'>";
echo $row['Game06'];
echo "</td><td class='v8'>";
echo $row['Game07'];
echo "</td><td class='v8'>";
echo $row['Game08'];
echo "</td><td class='v8'>";
echo $row['Game09'];
echo "</td><td class='v8'>";
echo $row['Game10'];
echo "</td><td class='v8'>";
echo $row['Game11'];
echo "</td><td class='v8'>";
echo $row['Game12'];
echo "</td><td class='v8'>";
echo $row['Game13'];
echo "</td><td class='v8'>";
echo $row['Game14'];
echo "</td><td class='v8'>";
echo $row['Game15'];
echo "</td><td class='v8'>";
echo $row['Game16'];
echo "</td><td class='v8'>";
echo $row['Survivor'];
echo "</td><td class='v8'>";
echo $row['Margin'];
echo "</td><td class='v8'>";
echo $row['Tiebreaker'];
echo "</td><td class='v8'>";
echo "$Winner";
echo "</td></tr>";

}

}

echo "</table>";
?>



</u>[/PHP]

$Game1Winner is correct variable for the winner of Game01

My table comes out with one red cell and the fields are pushed 1 spot to the right??


Any help would be great

Thanx,

Patsman77
Nov 25 '07 #1
5 4118
Markus
6,050 Expert 4TB
Line 4 you need to close your <TABLE> tag.

Also, in your 'if' statement, variables don't need to be surrounded with qoutes.

But i can't really see from your code what's wrong. Could you include the code that tells me what your variables $Game1 and $Game1Winner are doing..?
Nov 25 '07 #2
Here is my current code:

It is almost right, except, it pushes the fields over by 1 spot??

[PHP]$sql="select *from matchups where week='1'";
$result=mysql_query($sql);
while ($sql = mysql_fetch_object($result))
{
$pass[Week] = $sql -> Week;
$pass[Favorite] = $sql -> Favorite;
$pass[Underdog] = $sql -> Underdog;
$pass[Spread] = $sql -> Spread;
$pass[FavScore] = $sql -> FavScore;
$pass[UndScore] = $sql -> UndScore;
$pass[Time] = $sql -> Time;
$pass[Week] = $sql -> Week;
$pass[Favorite2] = $sql -> Favorite2;
$pass[Underdog2] = $sql -> Underdog2;
$pass[Spread2] = $sql -> Spread2;
$pass[FavScore2] = $sql -> FavScore2;
$pass[UndScore2] = $sql -> UndScore2;
$pass[Time2] = $sql -> Time2;



}
mysql_select_db("swammisp_swammisports", $con);
//mysql_select_db("sports", $con);
$sql2="select *from picksheet where user_name='$_SESSION[user_name]'";
$result=mysql_query($sql2);
while ($sql2 = mysql_fetch_object($result))
{
$pass[Game01] = $sql -> Game01;
$pass[Game02] = $sql -> Game02;
$pass[Game03] = $sql -> Game03;
$pass[Game04] = $sql -> Game04;
$pass[Game05] = $sql -> Game05;
$pass[Game06] = $sql -> Game06;
$pass[Game07] = $sql -> Game07;
$pass[Game08] = $sql -> Game08;
$pass[Game09] = $sql -> Game09;
$pass[Game10] = $sql -> Game10;
$pass[Game11] = $sql -> Game11;
$pass[Game12] = $sql -> Game12;
$pass[Game13] = $sql -> Game13;
$pass[Game14] = $sql -> Game14;
$pass[Game15] = $sql -> Game15;
$pass[Game16] = $sql -> Game16;
$pass[Survivor] = $sql -> Survivor;
$pass[Survivor2] = $sql -> Survivor2;
$pass[Margin] = $sql -> Margin;
$pass[High51] = $sql -> High51;
$pass[High52] = $sql -> High52;
$pass[High53] = $sql -> High53;
$pass[High54] = $sql -> High54;
$pass[High55] = $sql -> High55;
$pass[Tiebreaker] = $sql -> Tiebreaker;
$pass[Name] = $sql -> Name;
$pass[email] = $sql -> email;





}

$Winner=0;
$Game1Winner="R";
$Game2Winner="R";

// if/then/else Example
if (($pass[FavScore]-$pass[Spread]) > ($pass[UndScore])) {
echo "$pass[Favorite] is Winner.\n<p>"; ($Winner==$Winner++); ($Game1Winner="$pass[Favorite]");
} elseif (($pass[FavScore]-$pass[Spread]) < ($pass[UndScore])) {
// notice that PHP uses "elseif" instead of Perl's "elsif"
echo "$pass[Underdog] wins.\n", ($Game1Winner="$pass[Underdog]");
} else {
echo "Tie.\n";
}



if (($pass[FavScore2]-$pass[Spread2]) > ($pass[UndScore2])) {
echo "$pass[Favorite2] is Winner.\n<p>"; ($Winner==$Winner++); ($Game2Winner="$pass[Favorite2]");
} elseif (($pass[FavScore2]-$pass[Spread2]) < ($pass[UndScore2])) {
// notice that PHP uses "elseif" instead of Perl's "elsif"
echo "<p>$pass[Underdog2] wins.\n", ($Game2Winner="$pass[Underdog]");
} else {
echo "Tie.\n";
}


{
echo "<br>Winner of Game01 is $Game1Winner\n";
echo "<br>Winner of Game02 is $Game2Winner\n";
echo "<br>Total Wins is $Winner\n";

}
// Get all the data from the "example" table
$result = 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( $result )) {
// Print out the contents of each row into a table






{


echo "<tr><td class='v8'>";
echo $row['user_name'];
echo "</td><td class='v8'>";

if('$Game01'=='$Game1Winner')
{
print '<TH bgcolor="green">\n';
}
else
{
print '<TH bgcolor="red">\n';
}

echo $row['Game01'];
echo "</td><td class='v8'>";
echo $row['Game02'];
echo "</td><td class='v8'>";
echo $row['Game03'];
echo "</td><td class='v8'>";
echo $row['Game04'];
echo "</td><td class='v8'>";
echo $row['Game05'];
echo "</td><td class='v8'>";
echo $row['Game06'];
echo "</td><td class='v8'>";
echo $row['Game07'];
echo "</td><td class='v8'>";
echo $row['Game08'];
echo "</td><td class='v8'>";
echo $row['Game09'];
echo "</td><td class='v8'>";
echo $row['Game10'];
echo "</td><td class='v8'>";
echo $row['Game11'];
echo "</td><td class='v8'>";
echo $row['Game12'];
echo "</td><td class='v8'>";
echo $row['Game13'];
echo "</td><td class='v8'>";
echo $row['Game14'];
echo "</td><td class='v8'>";
echo $row['Game15'];
echo "</td><td class='v8'>";
echo $row['Game16'];
echo "</td><td class='v8'>";
echo $row['Survivor'];
echo "</td><td class='v8'>";
echo $row['Margin'];
echo "</td><td class='v8'>";
echo $row['Tiebreaker'];
echo "</td></tr>";
}
}

echo "</table>";
?>



</u>[/PHP]
Nov 25 '07 #3
Line 4 <table> tag is closed at bottom of code...


It is also not giving right color code for value assigned?


Thanx for the reply!!

Patsman77
Nov 25 '07 #4
After adding a second name with values of teams picked, the second name doesnt add up the win total correctly either...ughhh


Patsman77

I am very new to this, so please be patient with me..I am trying very hard to learn this!!
Nov 25 '07 #5
I figured it all out!!! Thanx for the help guys!

Patsman77
Nov 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
9
by: F. Da Costa | last post by:
Hi, Does anybody know why IE5+ does *not* honour array objects (like a table) across a session? Example: Frame A contains a var tableVar which is set via form Frame B (on init) using...
31
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a...
6
by: Eric | last post by:
I have an array, result. I populate the array and add it to an ArrayList. I then change result and add the new version to the ArrayList. However, when I go to review the ArrayList, all of the...
3
by: Nilz | last post by:
Hi all, i am using UltraWinGrid in my application and i want to change the Back Color of the Active Cell to transparent. i have defined CellClickAction as RowSelect. So if we click on the cell the...
7
by: Franck | last post by:
hello, I'm trying to change the color of certain cells in a datagrid according to their values? I tried to get the value in the Datagrid_ItemCreated event but I couldn't I don't know where...
0
by: Vikram | last post by:
I am changing parent cell of a combo at runtime suing table.rows(1).cells(2).add(cboname) earlier cboname is in cell 0 of row 2, and now i am changung its cell to cell 2 of row 1... But when...
3
by: Mad Scientist Jr | last post by:
Can someone post a clear example of how to change the background color of an individual datagrid cell for a Windows desktop app? (preferably in vb.net) I found some code on how to do this when...
1
by: K B | last post by:
I would like to create a gridview as below: Project Name 1-1 1-2 1-3 1-4 1-5 1-6 Project 1 BLUE BLUE BLUE BLUE GREEN GREEN more projects I would like to fill the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.