[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to change the color of table cell based on query result

Posted on 2006-05-10
6
Medium Priority
?
225 Views
Last Modified: 2013-12-24
I am trying to add some functionality to my CF calendar app.
One thing I want to do is add code that makes the cell of the table a different color when it is a holiday.

I already have code that makes the current day a different color.
How can I edit my code to do this.

Here is my first stab at it, but it is not working.
When the query td_set finds a day that is a holiday in the table, then I want the background color of the cell to be teal.

Help please.

      <TR bordercolor="cacaca" bordercolordark="cacaca">
<CFLOOP INDEX="ii" FROM="1" TO="#CalDays#">
                  <CFIF #ii# GTE #Offset# and #ii# LTE #LastSlot# >
                        <CFIF #day# IS #DayNum# AND #Month(#Now()#)# IS #MonthNum# AND #Year# IS  #DatePart("yyyy",#Now()#)#>

                        <TD valign=top WIDTH="200" height="40" BGCOLOR="whitesmoke" >
                                    </cfif>
      <CFQUERY Datasource="#dsn#" NAME="td_set">
      Select *
      From pmo
       Where firstout Between #MonthStart# and #MonthEnd# and grp='EVENTS_HOLIDAYS'
      </cfquery>
      
      <CFOUTPUT>
      <cfif #day# eq #td_set.firstout#>
      <TD valign=top WIDTH="200" height="40" BGCOLOR="teal">
      <cfelse>
      <TD valign=top WIDTH="200" height="40" border=0 bordercolor="cacaca" cellpadding="3" cellspacing="3" bordercolorlight="cacaca" bordercolordark="whitesmoke">
      </cfif>      
      </CFOUTPUT>            
0
Comment
Question by:g118481
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:mkishline
ID: 16649075
By just specifying td_set.firstout, you're only looking at the value for the first row returned from the td_set query.

<cfloop index="ii" from="1" to="#CalDays#">
      <cfif ii GTE Offset AND ii LTE LastSlot>
            <cfif day IS DayNum AND Month(Now()) IS MonthNum AND Year IS DatePart("yyyy",Now())>
                  <td valign="top" width="200" height="40" bgcolor="whitesmoke" >
            </cfif>
            
            <cfquery name="td_set" datasource="#dsn#">
                  SELECT *
                  FROM pmo
                  WHERE firstout BETWEEN #MonthStart# AND #MonthEnd#
                  AND grp='EVENTS_HOLIDAYS'
            </cfquery>
            
            <cfset isHoliday = "false" />
            <cfloop query="td_set">
                  <cfif day EQ firstout>
                        <cfset isHoliday = "true" />
                        <cfbreak />
                  </cfif>
            </cfloop>

            <cfif isHoliday>
                  <td valign="top" width="200" height="40" bgcolor="teal">
            <cfelse>
                  <td valign="top" width="200" height="40" border="0" bordercolor="cacaca" cellpadding="3" cellspacing="3" bordercolorlight="cacaca" bordercolordark="whitesmoke">
            </cfif>
0
 
LVL 1

Author Comment

by:g118481
ID: 16649531
I tested it, and your code does the exact same thing as mine.
The problem is that the loop is listing the days for the calendar cells from the array, but the query is not part of that array.  So, a table cell is being written for the query output, which is now blank and throws the calendar off by one cell.

Any ideas of how to fix it?
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 16650640
Let me know if this gets you closer...

<CFQUERY Datasource="#dsn#" NAME="td_set">
      Select *
      From pmo
      Where firstout Between #MonthStart# and #MonthEnd# and grp='EVENTS_HOLIDAYS'
</cfquery>

<TR bordercolor="cacaca" bordercolordark="cacaca">
      <CFLOOP INDEX="ii" FROM="1" TO="#CalDays#">
            <CFIF ii GTE Offset and ii LTE LastSlot>
                  <CFIF day IS DayNum AND Month(Now()) IS MonthNum AND Year IS DatePart("yyyy",Now())>
                        <TD valign=top WIDTH="200" height="40" BGCOLOR="whitesmoke" >
                  <cfelseif LISTFIND(valuelist(td_set.firstout),day)>
                        <TD valign=top WIDTH="200" height="40" BGCOLOR="teal">
                  <cfelse>
                        <TD valign=top WIDTH="200" height="40" border=0 bordercolor="cacaca" cellpadding="3" cellspacing="3" bordercolorlight="cacaca" bordercolordark="whitesmoke">
                  </cfif>    
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:g118481
ID: 16651393
Dan,

You are certainly on the right track.
I tested your code and it looks good, except that there is one problem.

The variable "firstout" is a date, but "day" is a number between 1 and 7.
I think that firstout needs to be converted to what number of the week it is (i.e. 1-7) and then compared to day.

I do not know how to do this, though.  
Any suggestions?

p.s.  I am incleasing the points for this questions.
0
 
LVL 15

Accepted Solution

by:
danrosenthal earned 2000 total points
ID: 16651535
First I would update this query:
<CFQUERY Datasource="#dsn#" NAME="td_set">
     Select day(firstout) AS firstoutdaynum
     From pmo
     Where firstout Between #MonthStart# and #MonthEnd# and grp='EVENTS_HOLIDAYS'
</cfquery>

Ten, update this line:
<cfelseif LISTFIND(valuelist(td_set.firstout),day)>

to be something like this instead:
<cfelseif LISTFIND(valuelist(td_set.firstoutdaynum),daynum)>

I'll leave the fine tuning to you, but that is the general idea I would follow.
-Dan
0
 
LVL 1

Author Comment

by:g118481
ID: 16651710
Dan,

Your suggestion works wonderfully.
Thanks again for your time and effort.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question