Skip to main content
October 10, 2008
Question

Cfdirectory question

  • October 10, 2008
  • 2 replies
  • 504 views
I have the code listed below being used to show images from a cfdirectory. However my problem is how do I get it to loop through the cfdirectory results as it now will print 4 cells of the same image and the move on to the next row instead of image 1 image 2 image 3 image 4 then another row.
    This topic has been closed for replies.

    2 replies

    Inspiring
    October 10, 2008
    PopcornCoder wrote:
    > I have the code listed below being used to show images from a cfdirectory.
    > However my problem is how do I get it to loop through the cfdirectory results
    > as it now will print 4 cells of the same image and the move on to the next row
    > instead of image 1 image 2 image 3 image 4 then another row.
    >
    > <table>
    > <cfoutput>
    >
    > <cfloop index="i" from="1" to="4">
    > <td align="center"><a href="#Name#"><img src="thumbs/#Name#" /><br
    > />#Name#</a></td>
    > </cfloop>
    >
    >
    > </cfoutput>
    > </table>
    >

    I don't see anywhere in this code where you are referencing the record
    set from the <cfdirectory...> call.

    I would expect to see something like <cfoutput query="myDirectory"> OR
    maybe #myDirectory.name # OR something that references the record set
    and iterates through it.

    The code you provided just repeats the same value of the #name# variable
    four times.
    October 10, 2008
    Ok how do I get the code to write the first 4 items, and then the next 4 items and the next for so I have

    <table><tr><td>item 1</td><td>item 2</td><td>item 3</td><td>item 4</td></tr>
    <tr><td>item 5</td><td>item 6<td><td>item 7</td><td>item 8</td></tr>
    </table>
    Inspiring
    October 10, 2008
    cfdirectory produces an query object. cfloop has a query attribute you can use.

    Details are in the cfml reference manual or livedocs.