I am wondering how to use a cfif statement to set the background color of a table cell based on the percentage number that is outputted from a db.
<td style="background-color:<cfif yourvalue lt 50>##333399;<cfelseif
[yourvalue] lt 75>##990000;<cfelse>##000000;</cfif>">#yourvalue#</td>
that may be a lot of cfif's though, depending how many values and cells
you have...
if your output table only shows one value on a row (instead of several
values side by side in columns), then you could do something like:
<table>
<cfoutut query="yourquery">
<cfif yourquery.yourvaluecolumn lt 50>
<cfset bgc = "##333399">
<cfelseif yourquery.yourvaluecolumn lt 75>
<cfset bgc = "##990000">
<cfelse>
<cfset bgc = "">
</cfif>
<tr><td style="background-color:#bgc#;">yourvalue</td></tr>
</cfoutput>
</table>

Signature
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Thanks I think I can work with that , it is to display results from a survey,
there are 137 answers, depending on the answer it will display a different
color, e.g. out of 1-4 ,if it is 3-4 it is green, if it is 2-3 it is yellow,
if is it below 2 it is red. it is the same for all the questions, to save code
is there a way to dynamically control it, using a loop.
Dan Bracuk - 30 Mar 2007 13:29 GMT
[q][i]Originally posted by: [b][b]scales76[/b][/b][/i]
Thanks I think I can work with that , it is to display results from a survey,
there are 137 answers, depending on the answer it will display a different
color, e.g. out of 1-4 ,if it is 3-4 it is green, if it is 2-3 it is yellow,
if is it below 2 it is red. it is the same for all the questions, to save code
is there a way to dynamically control it, using a loop.
[/q]
Do it in your query. In most db's except access, the syntax is
select case
when this = that then something
when this > that then something_else
else another_thing_altogether
end as an_alias
You might want to create an array of color values and use that instead of if /
loop stuff:
<cfset colors = arrayNew(1)>
<cfset colors[1] = "red">
<cfset colors[2] = "yellow">
<cfset colors[3] = "yellow">
<cfset colors[4] = "green">
(or whatever color values you need)
Then you can simply use colors[answer] as the color.
Hope that helps?