Skip to main content
July 24, 2008
Question

loop over query

  • July 24, 2008
  • 3 replies
  • 304 views
I have an access database table that contains a column that I would change all the values to the same variable. The table is forever being populated with more rows as data is entered regularly. I have tried numerous attempts to build an insert query inside cfloop tags and I never seem to get the right result. Here is a snipet.

<cfif FORM.Updated IS "no">
<CFLOOP INDEX="Update" LIST="#FORM.Updated#">
<CFQUERY Name="#Update#" DataSource="#db#">
INSERT INTO QTYTracking (Updated)
VALUES ('#FORM.Updated#')</CFQUERY></CFLOOP>
</cfif>
    This topic has been closed for replies.

    3 replies

    Inspiring
    July 24, 2008
    chrispilie wrote:
    > AH... Lazy copy and paste error. The UPDATE worked. Time for some coffee!

    I presume that means you correct your INSERT|UPDATE logic so that you
    get a different value each loop? Because in your original post, the
    logic would produce the same value for every record put|changed in the
    database.

    <CFLOOP INDEX="Update" LIST="#FORM.Updated#">
    <CFQUERY Name="#Update#" DataSource="#db#">
    INSERT INTO QTYTracking (Updated)
    VALUES ('#FORM.Updated#')</CFQUERY></CFLOOP>
    </cfif>


    If form.Updated equaled the list 'red,white,blue' Then three values
    would be put into the database, but the 'Updated' column of all three
    would equal 'red,white,blue'. I would usually expect a loop like this
    to put three separate values and thus it would look something like this.

    <CFLOOP INDEX="Update" LIST="#FORM.Updated#">
    <CFQUERY Name="#Update#" DataSource="#db#">
    INSERT INTO QTYTracking (Updated)
    VALUES ('#Update#')</CFQUERY></CFLOOP>
    </cfif>

    But maybe that is not the desired result.
    July 24, 2008
    AH... Lazy copy and paste error. The UPDATE worked. Time for some coffee!
    Inspiring
    July 24, 2008
    quote:

    Originally posted by: chrispilie
    AH... Lazy copy and paste error. The UPDATE worked. Time for some coffee!

    When you come back, look at your code again and figure out how to do it without a loop.
    Inspiring
    July 24, 2008
    You realize that insert queries don't update existing rows, right?