Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-21-2010, 10:48 PM   PM User | #1
iikon
New Coder

 
Join Date: May 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
iikon is an unknown quantity at this point
css help

I have something that i am hoping is simple, have a small php script and i want the background of one of the td to change according to the value from the database. for example if the number from the database is between 1000 & 2000 then i want the color to be "#fff" if the number is between 2000 & 3000 then i want it to be "#000" and so on with probably with about 10 possibilities, is this possible in css or will i need to use a javascript? Any help would be truely appreciated.

Last edited by iikon; 11-21-2010 at 10:52 PM..
iikon is offline   Reply With Quote
Old 11-22-2010, 12:01 AM   PM User | #2
BulletTimeBill
Regular Coder

 
Join Date: May 2010
Location: Bathurst, Australia
Posts: 180
Thanks: 1
Thanked 22 Times in 22 Posts
BulletTimeBill is an unknown quantity at this point
I'd use php. You can "jump" in and out of php when ever you want eg.
Code:
if ($foo >1000 && $foo <2000){?>
<style>
element{
background:#fff;
}
</stlye>
<?php } ?>
I'd try to put that in the head somewhere if possible.
...also,don't presume my syntax is correct, i just woke up.
BulletTimeBill is offline   Reply With Quote
Old 11-22-2010, 01:38 AM   PM User | #3
Afro_Programmer
Regular Coder

 
Join Date: Sep 2010
Location: Virginia
Posts: 112
Thanks: 11
Thanked 7 Times in 7 Posts
Afro_Programmer is an unknown quantity at this point
That's php territory, you could do it w/ JavaScript too but php is the most obvious way.

Since you have like 10 possibilities, use a switch statement.

PHP Code:
<style type = "text/css">

.className
{
color: <?php

switch($var)
{
case (
$var 5000): echo "#FFF;";
break;
case..........
}
?>
}

</style>
I'm not sure if the syntax on that case will work. If it evaluates to true, it should print your color, if not, it should go down to the next case. Just play around w/ it and see though.

Last edited by Afro_Programmer; 11-22-2010 at 01:41 AM..
Afro_Programmer is offline   Reply With Quote
Old 11-22-2010, 01:39 AM   PM User | #4
iikon
New Coder

 
Join Date: May 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
iikon is an unknown quantity at this point
Ok I am not familiar enough with what you are talking about, If you can give me a little more would greatly appreciated
iikon is offline   Reply With Quote
Old 11-22-2010, 02:01 AM   PM User | #5
Afro_Programmer
Regular Coder

 
Join Date: Sep 2010
Location: Virginia
Posts: 112
Thanks: 11
Thanked 7 Times in 7 Posts
Afro_Programmer is an unknown quantity at this point
PHP Code:
<style type = "text/css">

.className
{
color: <?php

switch($var)
{
case (
$var 1000 && $var 2000): echo "#FFF;";
break;
case (
$var 2000 && $var 3000): echo "#FFF;";
break;
.... 
//other cases go there
default: "#000";
}
?>
}

</style>

Last edited by Afro_Programmer; 11-22-2010 at 04:52 PM..
Afro_Programmer is offline   Reply With Quote
Old 11-22-2010, 02:44 AM   PM User | #6
iikon
New Coder

 
Join Date: May 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
iikon is an unknown quantity at this point
ok that i got but when i use it it makes everything greater than the first number the first row color, i dont know what else to change
iikon is offline   Reply With Quote
Old 11-22-2010, 03:53 AM   PM User | #7
iikon
New Coder

 
Join Date: May 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
iikon is an unknown quantity at this point
This is what i had for the stylesheet

Code:
.defenselose
{
color:#FF0000;
font-size: 12;
font-weight:bold;
background-color: <?php
switch($var)
{
case ($var > 0 && $var < 1000): echo "#FFF;";
break;
case ($var > 1000 && $var < 2000): echo "#FFFF00;";
break;
case ($var > 2000 && $var < 2500): echo "#66FF99;";
break;
case ($var > 2500 && $var < 3000): echo "#E0C760;";
break;
case ($var > 3000 && $var < 3500): echo "#669999;";
break;
case ($var > 3500 && $var < 4000): echo "#9933FF;";
break;
case ($var > 4500 && $var < 5000): echo "#CC6666;";
break;
case ($var > 5000 && $var < 5500): echo "#0066FF;";
break;
case ($var > 5500 && $var < 6000): echo "#006633;";
break;
case ($var > 6500 && $var < 7000): echo "#666666;";
break;
case ($var > 7000 && $var < 8000): echo "#996600;";
break;
case ($var > 8000 && $var < 9000): echo "#FF00FF;";
break;
case ($var > 9000 && $var < 10000): echo "#330000;";
break;
case ($var > 10000 && $var < 12500): echo "#66FF00;";
break;
case ($var > 12500 && $var < 15000): echo "#333333;";
break;
case ($var > 15000 && $var < 20000): echo "#CC99FF;";
break;
case ($var > 20000 && $var < 30000): echo "#CCCCFF;";
break;
case ($var > 30000 && $var < 40000): echo "#993300;";
break;
case ($var > 40000 && $var < 5000): echo "#660099;";
break;
case ($var > 40000 ): echo "#000;";
break;
default: "#000"; 
} 
?> 
}
And all of the Background colors were White from
Code:
 case ($var > 0 && $var < 1000): echo "#FFF;";

Last edited by iikon; 11-22-2010 at 03:55 AM..
iikon is offline   Reply With Quote
Old 11-22-2010, 05:05 AM   PM User | #8
santhoshj400
Banned

 
Join Date: Jul 2010
Posts: 66
Thanks: 0
Thanked 1 Time in 1 Post
santhoshj400 is an unknown quantity at this point
Hi,
Nice posts I was searching for this type of scripts thanks and keep posting
santhoshj400 is offline   Reply With Quote
Old 11-22-2010, 04:44 PM   PM User | #9
Afro_Programmer
Regular Coder

 
Join Date: Sep 2010
Location: Virginia
Posts: 112
Thanks: 11
Thanked 7 Times in 7 Posts
Afro_Programmer is an unknown quantity at this point
Quote:
Originally Posted by iikon View Post
This is what i had for the stylesheet

Code:
.defenselose
{
color:#FF0000;
font-size: 12;
font-weight:bold;
background-color: <?php
switch($var)
{
case ($var > 0 && $var < 1000): echo "#FFF;";
break;
case ($var > 1000 && $var < 2000): echo "#FFFF00;";
break;
case ($var > 2000 && $var < 2500): echo "#66FF99;";
break;
case ($var > 2500 && $var < 3000): echo "#E0C760;";
break;
case ($var > 3000 && $var < 3500): echo "#669999;";
break;
case ($var > 3500 && $var < 4000): echo "#9933FF;";
break;
case ($var > 4500 && $var < 5000): echo "#CC6666;";
break;
case ($var > 5000 && $var < 5500): echo "#0066FF;";
break;
case ($var > 5500 && $var < 6000): echo "#006633;";
break;
case ($var > 6500 && $var < 7000): echo "#666666;";
break;
case ($var > 7000 && $var < 8000): echo "#996600;";
break;
case ($var > 8000 && $var < 9000): echo "#FF00FF;";
break;
case ($var > 9000 && $var < 10000): echo "#330000;";
break;
case ($var > 10000 && $var < 12500): echo "#66FF00;";
break;
case ($var > 12500 && $var < 15000): echo "#333333;";
break;
case ($var > 15000 && $var < 20000): echo "#CC99FF;";
break;
case ($var > 20000 && $var < 30000): echo "#CCCCFF;";
break;
case ($var > 30000 && $var < 40000): echo "#993300;";
break;
case ($var > 40000 && $var < 5000): echo "#660099;";
break;
case ($var > 40000 ): echo "#000;";
break;
default: "#000"; 
} 
?> 
}
And all of the Background colors were White from
Code:
 case ($var > 0 && $var < 1000): echo "#FFF;";
Don't get offended but I gotta ask, what is the name of the variable in your script? Is it $var or something else? ;o
Afro_Programmer is offline   Reply With Quote
Old 11-22-2010, 06:21 PM   PM User | #10
iikon
New Coder

 
Join Date: May 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
iikon is an unknown quantity at this point
that i am not sure about, let me look through and see what i can find, again i am new to this

Code:
$defwin = $u['defwin'];
i think that is what you are talking about right?

Last edited by iikon; 11-22-2010 at 06:31 PM..
iikon is offline   Reply With Quote
Old 11-22-2010, 07:17 PM   PM User | #11
Afro_Programmer
Regular Coder

 
Join Date: Sep 2010
Location: Virginia
Posts: 112
Thanks: 11
Thanked 7 Times in 7 Posts
Afro_Programmer is an unknown quantity at this point
Quote:
Originally Posted by iikon View Post
that i am not sure about, let me look through and see what i can find, again i am new to this

Code:
$defwin = $u['defwin'];
i think that is what you are talking about right?
I don't know. Is that the variable that holds the number that you want? If it is, then go for it.
Afro_Programmer is offline   Reply With Quote
Old 11-22-2010, 08:28 PM   PM User | #12
iikon
New Coder

 
Join Date: May 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
iikon is an unknown quantity at this point
thats it, but here is the link to the Page

http://www.tspclan.com/SS/test.php?id=156

As you can see, the 2 center columns are yellow and i dont know how to fix it that way obviously is not working, i am lost lol
iikon is offline   Reply With Quote
Old 11-22-2010, 11:04 PM   PM User | #13
iikon
New Coder

 
Join Date: May 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
iikon is an unknown quantity at this point
Anyone else have anything this is what i have right now & it just chows a black bg on my cell

Code:
.defensewin
{
color:#FF0000;
font-size: 12;
font-weight:bold;
background-color: <?php
switch($defwin)
{
case ($defwin <= 1000): echo "#FFF;"; break;
case ($defwin <= 2000): echo "#FFFF00;"; break;
case ($defwin <= 2500): echo "#66FF99;"; break;
case ($defwin <= 3000): echo "#E0C760;"; break;
case ($defwin <= 4000): echo "#669999;"; break;
case ($defwin <= 4500): echo "#9933FF;"; break;
case ($defwin <= 5000): echo "#CC6666;"; break;
case ($defwin <= 5500): echo "#0066FF;"; break;
case ($defwin <= 6000): echo "#006633;"; break;
case ($defwin <= 7000): echo "#666666;"; break;
case ($defwin <= 8000): echo "#996600;"; break;
case ($defwin <= 9000): echo "#FF00FF;"; break;
case ($defwin <= 10000): echo "#330000;"; break;
case ($defwin <= 12500): echo "#66FF00;"; break;
case ($defwin <= 15000): echo "#333333;"; break;
case ($defwin <= 20000): echo "#CC99FF;"; break;
case ($defwin <= 30000): echo "#CCCCFF;"; break;
case ($defwin <= 40000): echo "#993300;"; break;
case ($defwin <= 50000): echo "#660099;"; break;
case ($defwin > 50000 ): echo "#000;"; break;
default: "#000"; break;
} 
?> 
}
Would be open to any other ideas
iikon is offline   Reply With Quote
Old 11-22-2010, 11:12 PM   PM User | #14
Afro_Programmer
Regular Coder

 
Join Date: Sep 2010
Location: Virginia
Posts: 112
Thanks: 11
Thanked 7 Times in 7 Posts
Afro_Programmer is an unknown quantity at this point
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">

.change
{
	
	
	background-color: #<?php
	
	$var = 5;
	switch($var)
	{
		case ($var > 0 && $var < 1000): echo "bfc6de;";
		break;
		case ($var > 1000 && $var < 2000): echo "92d917;";
		break;
		default: echo "ff6406;";
	}
	
	?>
	
	border: 2px solid #093;
	width: 5em;
}

</style>
</head>

<body>

<p class="change">cool a box </p>

</body>
</html>
This works for me. If I change the $var variable to fit one of the test conditions, it gives the correct color. So maybe there's something wrong with the value you're pulling from the database.

Last edited by Afro_Programmer; 11-22-2010 at 11:24 PM..
Afro_Programmer is offline   Reply With Quote
Old 11-23-2010, 01:41 AM   PM User | #15
iikon
New Coder

 
Join Date: May 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
iikon is an unknown quantity at this point
stupid question but what is the $var=5; ?
iikon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:48 AM.


Advertisement
Log in to turn off these ads.