Solved

How to use currentrow or mod to get first and third record for CSS use

Posted on 2014-01-28
6
465 Views
Last Modified: 2014-01-28
How can I figure out every first and third record to use css styling.  I need to do 3 items per row, so I need to identify the first and third of every row in a loop.
0
Comment
Question by:theideabulb
  • 3
  • 3
6 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 39816401
If you just want to create a new row every three items use MOD 3. A simple demo example with tables:

<table>
<tr>
    <cfoutput query="someQuery">
        <td>#currentRow#</td>
        <!--- start a new row every three cells --->
        <cfif currentRow MOD 3 EQ 0>
            </tr><tr>
        </cfif>
    </cfoutput>
</tr>
</table>


Otherwise, can you give an example of what you mean? ie Do you mean every other row?

row 1:   find this row
row 2:   ignore
row 3:   find this row
row 4:   ignore
row 5:   find this row
row 6:   ignore

EDIT: If yes, just change the CF code to "currentRow MOD 2 EQ 0". Another option is jQuery's "odd" selector:

http://api.jquery.com/odd-selector/
0
 

Author Comment

by:theideabulb
ID: 39816409
What happens if it ends on an something different like

123
456
78
0
 

Author Comment

by:theideabulb
ID: 39816415
Basically I need to do something like this:

<div class="row">

 1   2    3

</div>
<div class="row">

4    5   6
</div>
<div class="row">
7      8
</div>


so i need to start every row with
<div class="row">  and on every third record close it with </div>
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39816429
Just figure what the MOD is on the 1st and 3rd row and add a CFIF for both.

<cfoutput query="someQuery">

     <!--- when it's the 1st row the remainder is always 1--->
     <cfif currentRow MOD 3 EQ 1> <div class="row"></cfif>

    ... do stuff here ...

     <!--- if it's the 3rd row the remainder is always 0 --->
     <!--- also close the DIV when it's the last row in the query --->
     <cfif currentRow MOD 3 EQ 0 OR currentRow EQ someQuery.recordCount> </div></cfif>

</cfif>
0
 

Author Closing Comment

by:theideabulb
ID: 39816436
PERFECT!!!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39816438
Glad it helped. Btw, not sure if you saw the edit, but I added an extra condition to close the <div> when it's the final row of the query too.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 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