Copy link to clipboard
Copied
I was on a website and saw that they had their results displaying in a row of 3 then it <br/> to the next row. I have been searching high and low for days on how they did that. I know it can be done manually, but the question is if it can be done dynamically?
For example:
Search results = 37
I would like to display it as follows
Result # 1 :: Result # 2 :: Result # 3 <br/>
Result # 4 :: Result # 5 :: Result # 6 <br/>
Result # 7 :: Result # 8 :: Result # 9 <br/>
and so on.
Hope that all makes sense.
I found an old string on the forums here with someone having the same issue. The following is exactly what i needed to finish this. I had no clue how to complete this. Dan's reply was right, but i didn't know exactly how to finish it to account for the last part of the record.
<cfif ((CurrentRow MOD 3) EQ 0) or (CurrentRow eq RecordCount)>
</tr>
<cfif CurrentRow lt RecordCount>
<tr>
</cfif>
</cfif>
Thanks again to everyone for the replies and help.
Copy link to clipboard
Copied
Yes, you can do this using the MOD operator, which returns the remainder from division. Using this, you can identify numbers that are evenly divisible within other numbers.
<cfif x mod 3 is "0">
</tr><tr>
</cfif>
Dave Watts, CTO, Fig Leaf Software
Copy link to clipboard
Copied
Thanks for the reply Dave.
I tried it in the code, but it didn't seem to work. I used CurrentRow and RecordCount functions where the X is and it doesn't display the first 3 on the same row then break on the 3rd one. Here's the code if it helps.
--------------- Code ----------------
<cfquery datasource="poll" name="qInfo">
SELECT FirstName, LastName, Party, PersonID, Island
FROM PersonInfo
ORDER BY FirstName
</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table cellspacing="5">
<cfoutput query="qInfo">
<tr>
<td>
<a href="../persons/?Person=#PersonID#">#FirstName# #LastName#</a><br />
#Party#
</td>
<cfif qInfo.CurrentRow MOD 3 is "0">
</tr><tr>
</cfif>
</cfoutput>
</table>
</body>
</html>
------------------- End Code ------------------
I again i tried both functions.
Copy link to clipboard
Copied
Problem Number 1:
<cfoutput query="qInfo">
<tr>
Those two lines should be reversed.
Problem Number 2:
<cfif qInfo.CurrentRow MOD 3 is "0">
</tr><tr>
</cfif>
</cfoutput>
</table>
This is incomplete. You need to account for the last record or two in your query results. If you leave it unchanged, you will be missing a closing tr tag.
Copy link to clipboard
Copied
I found an old string on the forums here with someone having the same issue. The following is exactly what i needed to finish this. I had no clue how to complete this. Dan's reply was right, but i didn't know exactly how to finish it to account for the last part of the record.
<cfif ((CurrentRow MOD 3) EQ 0) or (CurrentRow eq RecordCount)>
</tr>
<cfif CurrentRow lt RecordCount>
<tr>
</cfif>
</cfif>
Thanks again to everyone for the replies and help.