ODBiC Discussion Board


WHILE Loop within an IMPORT loop?

by David RIchardson, November 12, 2004 12:50

Hi,

There may well be an easier way to do this, but I'm trying to IMPORT a CSV file into a page. The only trouble is that I won't know in advance what the field headers will be.

I thought that I could grab the first line from the CSV file with an IMPORT LINE command, and then break after the first line, which would give me the field names.

I then thought that I could use the $split() function to then separate these out into individual field names using a WHILE loop, but it never gets past the first row. It could be that I've got my code wrong, so I've included it below.

If I *am* doing this the wrong way, then please enlighten me! :-)

<% IMPORT line from $tempfile$.csv %> <!--SET columnimport=$repl($line$,'"'='')--> <!--IF $importrow$=1--><!--BREAK--><!--ENDIF--> <% ENDIMPORT %>

<% IMPORT DELIMITER=",",QUOTED, $columnimport$ from $tempfile$.csv %>

<!--WHILE $columnimport$--> <!--SET thisfield=$split(columnimport,",")--> $var($thisfield$) <!--ENDWHILE--> <br> <% ENDIMPORT %>



Replies:


Post Your Reply:

Name   
E-mail  optional
Topic  
Message:

HTTP Link: 
Link text: 


Copyright ©1997-2003, Roger Harris. All rights reserved.