Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to display results in 3s then line break it?

Guest
Feb 08, 2012 Feb 08, 2012

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.

714
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Feb 13, 2012 Feb 13, 2012

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.

Translate
Community Expert ,
Feb 08, 2012 Feb 08, 2012

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

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 10, 2012 Feb 10, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 10, 2012 Feb 10, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 13, 2012 Feb 13, 2012
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources