Solved

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

Posted on 2014-01-28
6
472 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

752 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