...

View Full Version : css help



iikon
11-21-2010, 11:48 PM
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.

BulletTimeBill
11-22-2010, 01:01 AM
I'd use php. You can "jump" in and out of php when ever you want eg.


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.

Afro_Programmer
11-22-2010, 02:38 AM
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.



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

iikon
11-22-2010, 02:39 AM
Ok I am not familiar enough with what you are talking about, If you can give me a little more would greatly appreciated

Afro_Programmer
11-22-2010, 03:01 AM
<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>

iikon
11-22-2010, 03:44 AM
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
11-22-2010, 04:53 AM
This is what i had for the stylesheet


.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
case ($var > 0 && $var < 1000): echo "#FFF;";

santhoshj400
11-22-2010, 06:05 AM
Hi,
Nice posts I was searching for this type of scripts thanks and keep posting

Afro_Programmer
11-22-2010, 05:44 PM
This is what i had for the stylesheet


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

iikon
11-22-2010, 07:21 PM
that i am not sure about, let me look through and see what i can find, again i am new to this



$defwin = $u['defwin'];


i think that is what you are talking about right?

Afro_Programmer
11-22-2010, 08:17 PM
that i am not sure about, let me look through and see what i can find, again i am new to this



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

iikon
11-22-2010, 09:28 PM
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
11-23-2010, 12:04 AM
Anyone else have anything this is what i have right now & it just chows a black bg on my cell



.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

Afro_Programmer
11-23-2010, 12:12 AM
<!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.

iikon
11-23-2010, 02:41 AM
stupid question but what is the $var=5; ?

EMaks
11-23-2010, 02:15 PM
This is definition of $var for test purposes, In your case, you should get this number from your database. You shouldn't define it like that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum