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

delimited input cfloop

New Here ,
Sep 09, 2010 Sep 09, 2010

I am trying to use a list of delimited values and put it in a database. The list is setup as follows:

siteId|SiteName|siteURL|galleryURL|descript|dateAdded|type;

siteId|SiteName|siteURL|galleryURL|descript|dateAdded|type;

siteId|SiteName|siteURL|galleryURL|descript|dateAdded|type;

As you can see the values are delimited by pipe and each one has a semi-colon on the end. I have comprised the follow code that doesn't seem to work. What is wrong? (Assuming its gets passed the form.txtBox1 from a seperate script.

<cfloop index="gallery" list="#form.txtBox1#" delimiters="|">

    <cfquery name="importList">

         INSERT INTO gallery (siteId,siteName,siteUrl,galleryUrl,descript,dateAdded,type)

         VALUES

                  ('#listgetAt('#gallery#',1, '|')#',

                   '#listgetAt('#gallery#',2, '|')#',

                   '#listgetAt('#gallery#',3, '|')#',

   '#listgetAt('#gallery#',4, '|')#',

   '#listgetAt('#gallery#',5, '|')#',

   '#listgetAt('#gallery#',6, '|')#',

   '#listgetAt('#gallery#',7)#'

                  )

   </cfquery>

</cfloop>

676
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

Valorous Hero , Sep 09, 2010 Sep 09, 2010

cfloop delimiters="|"

At a glance the cfloop delimiter (ie row) should probably be ";"

'#listgetAt('#gallery#',7)#'

... and you are missing the '|' delimiter for the last item.

If there is a chance the elements might be empty, consider using arrays instead. Unlike most list functions, listToArray() in CF8+ is capable of preserving empty elements. Also, queries executed within a loop are prime candidates for cfqueryparam.

-Leigh

Translate
Valorous Hero ,
Sep 09, 2010 Sep 09, 2010

cfloop delimiters="|"

At a glance the cfloop delimiter (ie row) should probably be ";"

'#listgetAt('#gallery#',7)#'

... and you are missing the '|' delimiter for the last item.

If there is a chance the elements might be empty, consider using arrays instead. Unlike most list functions, listToArray() in CF8+ is capable of preserving empty elements. Also, queries executed within a loop are prime candidates for cfqueryparam.

-Leigh

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 ,
Sep 10, 2010 Sep 10, 2010

In addition to cfSearching's answer, you appear to be storing DateAdded as a string instead of a date.  Bad idea.

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
New Here ,
Sep 10, 2010 Sep 10, 2010
LATEST

That is correct. I was able to do the task and got the error about the date string. I will have to re-think the date field. Thanks the help guys.

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