Go Premium for a chance to win a PS4. Enter to Win

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
?
508 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
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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
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. …
Suggested Courses

885 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