Solved

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

Posted on 2014-01-28
6
443 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now