Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-28
6
Medium Priority
?
500 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

718 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