Mod function

I use the following to output my query results:


<cfoutput>
	<ul class="gallery">
		<cfloop query="getEventgallery">
  	<cfset modStyle = currentRow mod 3>
			<li class="gal#modStyle#"><a href="#link#" rel="prettyPhoto" title="#description#"><img src="event_gallery/#photo#" alt="#description#" /></a></li>
  	</cfloop>
	</ul>
</cfoutput>

I use the mod function to style the third <li> in each row! I’m looking for a way to fill up the last row with default images in case there are not enough records in the database to fill up the row.

so, from what I understand…*you’re wanting at LEAST x images in the last row.
So, if x = 10 and your query only has 8, you need 2 images to fill up the unused space, correct?

If that’s right, I’m confused as to what the mod function has to do with this.

<cfoutput>
    <ul class="gallery">
        <cfset intRowCount = 12 />
        <cfset intCellsPerRow = 4 />
        <cfloop from="1" to="#( ceiling( intRowCount / intCellsPerRow ) * intCellsPerRow )#" index="currentrow">
            <cfif currentRow lte intRowCount>
                <cfif currentRow mod intCellsPerRow neq 0>
                    <li>Normal - #currentrow#</li>
                <cfelse>
                    <li>Styled - #currentrow#</li>
                </cfif>
            <cfelse>
                <li>Empty - #currentrow#</li>
            </cfif>
        </cfloop>
    </ul>
</cfoutput>

For the example above, I used 2 variables, intRowCount (which is your query’s RECORDCOUNT attribute) and intCellsPerRow, which defines which index of the LI gets styled. If there are “empty” rows afterwards, they are filled with the LI “empty”.

I used Mod to style the third (0) record in every row but this works great thanks.