0

I have written the following query which functions exactly as I have planned:

<cfquery name="myquery" datasource="abc">
SELECT DISTINCT Right((Format([vDatum],"yyyy")),2) AS DDate
FROM tVCal RIGHT JOIN tVEvents ON tVCal.VItem = tVEvents.EvDate
</cfquery>

Every time this query is run, it outputs a series of two digit year numbers corresponding to years between 1940 and 2039, for which data is available in the database, for example: 00,04,15,28,42,56,58,75,89

Then I have a non-varying list of all year numbers from (19)40 to (20)39 arranged in tabular form, with the first decade looking like this:

<tr><td>40</td><td>41</td><td>42</td><td>43</td><td>44</td><td>45</td><td>46</td><td>47</td><td>48</td><td>49</td>       
</tr>

Every time this table is displayed and the document is ready, I need a CF or jQuery function which will format all of the year numbers red which were also contained in the output from the original query.

Ten years ago I might have been able to write this myself, but I will be 80 this year and my head swims whenever I try something new. And if I am in the wrong place here, I would be grateful for a hint on where to go. Frank

1 Answer 1

2

You could try something like this:

<cfoutput>
<table>
<tr>
<cfloop list = "#YourListOfNumbers#" index = "number">
<cfset ThisColour = ListFind(ValueList(myquery,DDate), number) ? "red" : "black">
    
<td style = "Color:#ThisColour#">#number#</td>
    
</cfloop>
</tr>
</table>
</cfoutput>

You'll need to put in some extra work to get more than one row, but that's not part of the question.

A sample of this logic is available here ==> https://trycf.com/gist/dcedc5c1264a4ce18a91ce496a8c0405/lucee5?theme=monokai

Sign up to request clarification or add additional context in comments.

10 Comments

I just now read your suggestion, Dan, because of the time zone difference here in Europe. Since I have 100 List items, I shall have to decide whether to make an internal loop for the ten table rows or to code all 100 rows discreetly. SO frowns upon using the word "thanks" in comments, so I will just say "danke schön"!
When I run your code in my page CF says I have no closing tag for <cfscript>. A bald-faced lie, like so many idiotic CF error messages. I will keep hacking away...
Here is a way to put your 100 numbers into 10 rows. trycf.com/gist/b32727037961d3c2a30bc5c52c8195f6/…
That worked nicely for me, I just need to add leading zeroes to the numbers 0 - 9.
"...need to add leading zeroes...." Why not just loop from 1940 to 2039 and format the year number on output? trycf.com/gist/08a28ddc8aa8f384ce00eb4d962f6e06/… "..no closing tag for <cfscript>..." As an aside, there's no benefit to mixing cfscript and cfml syntax in this context. You may find it easier to stick with one style.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.