开发者

cfoutput looping on one file name

According to LiveDocs for cfoutput in cf7:

When you specify a query attribute, this tag loops over the query rows and produces output for each row within the range specified by the startRow and maxRows values

I'm trying to grab the names of the files in a directory. I use a cfdirectory to get a query record then query the query with cfquery. My cfoutput loops the number of rows of the query, but lists the same file name each time:

output: alt text http://img80.imageshack.us/img80/9294/onefile.png

code:

  <!-- list fi开发者_开发问答les in pass-fail directory -->
  <cfset fileLocation = "c:\YouTubeUploader\pass-fail">
  <cfdirectory 
    action = "list"
    directory = "#fileLocation#"
    name = "files"
    > <!-- master query -->

     <cfdump var="#files#" label="files in pass-fail" > 
      <!-- displays the query record set returned from cfdirectory -->

      <!-- detail query generates a new query result set - the names of the files  -->
        <cfquery dbtype="query" name="detail"> 
SELECT files.name
 FROM files
      </cfquery>

     <!-- output all file names -->
     <cfoutput query="detail"  startRow = "1"
            maxRows = "5">
     #files.Name#<br>  
       </cfoutput>

Why is cfoutput staying on that one file name?


the reason is because cf is thinking you want the name value of the files query since you named your variable in your detail query files.name. change your details query to read:

SELECT name FROM files

and then change your out to read:

<cfoutput query="detail"  startRow = "1" maxRows = "5">#detail.name#<br></cfoutput>

and everything should be cool.


Within your cfoutput query loop change #files.Name# to #detail.Name# and that should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜