• home
  • forum
  • my
  • kt
  • download
  • Horizontal Loop

    Author: 2009-02-27 10:28:05 From:

    Many of you may have had a time when you have wanted to output from a query in a grid format.

    This script will enable you to loop through the results horizontally, across the screen

    Here is a demo of the result

    The first thing that we need to do it to query a database

    <cfquery datasource="loop" name="items">
    SELECT *
    FROM table
    </cfquery>

    Now that we have the data we can decide how many columns we would like across the screen in this example i will have 5. I will set a variable to that after every 5th result i will start a new line.

    <cfset multiple = 5>

    We will now create a table to output the data into. within this table we will repeat the <td> tag and after every 5th result output </tr><tr> to end the line and start a new one. we will then increase the count for the end of the next row.

    <table width="300" border="0" cellspacing="1" cellpadding="1">
    <tr>
    <cfoutput query="items">
    <td#items.name#</td>
    <cfif CurrentRow eq multiple>
    </tr><tr>
    <cfset multiple = multiple + 5>
    </cfif>
    </cfoutput>
    </tr>
    </table>

    Here is the full script for you

    <cfquery datasource="loop" name="items">
    SELECT *
    FROM table
    </cfquery>
    <cfset multiple = 5>
    <table width="300" border="0" cellspacing="1" cellpadding="1">
    <tr>
    <cfoutput query="items">
    <td>#items.name#</td>
    <cfif CurrentRow eq multiple>
    </tr><tr>
    <cfset multiple = multiple + 5>
    </cfif>
    </cfoutput>
    </tr>
    </table>

    Enjoy

    discuss this topic to forum

    relation tutorial

    No information

    New

    Hot