Iterative Insert with Variable Field Name

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Iterative Insert with Variable Field Name

    Hello,

    Someone must have come across this already, I need help with this insert query
    I have.

    I have a form that has variables as such:
    blurb1title ->blurb5title
    blurb1url ->blurb5url
    blurb1desc ->blurb5desc

    I'd like to iterativelly insert them into a db like so

    INSERT INTO blurbs
    (source, blurbtitle,blurburl, blurbdesc)
    values
    (#source#, #blurbtitle#, #blurburl#,blurbdesc#)

    How can I loop through that insert statement changing the value of
    #blurbtitle#, #blurburl#, #blurbdesc#?

    so my table will look like this at the end:

    source blurbtitle blurburl blurbdesc
    ====== ====== ====== =========
    abc1 title1 url1 desc1
    abc1 title2 url2 desc2
    etc..

    :confused;

    Loony2nz Guest

  2. Similar Questions and Discussions

    1. Insert ASP variable into SQL table
      Hi, I have a variable called 'pSKU' (without quotes) that holds the SKU of a product. When someone visits a product page, I would like it to...
    2. Insert TAB into calculated field
      I'm trying to create a function with FM Pro 4.1 where a user can click a button on a screen causing a group of five fields to be copied into the...
    3. Insert Date into Memo Field
      I wold like to be able to insert a date into a memo field. I have a form that sets the date and then copies it into the field into a bound control,...
    4. Insert a file in a SQL field
      You can store the file in a column with datatype image. This holds up to 2GB of binary data. -- Jacco Schalkwijk MCDBA, MCSD, MCSE Database...
    5. How to Insert documents to a BLOB field
      Hi, I have an Access Front-End application and an Oracle Back-End for my tables. I have a BLOB field in one of the tables. I use Access form to...
  3. #2

    Default Re: Iterative Insert with Variable Field Name

    Nevermind. I had a friend help me out.

    Here is the solution:
    <CFLOOP index="count" from="1" to="5" step="1">
    <CFSET blurbtitle=form["blurb#count#title"]>
    <CFSET blurbURL=form["blurb#count#url"]>
    <CFSET blurbDESC=form["blurb#count#desc"]>
    INSERT INTO tblNewsLetterBlurb
    (ctsrc,blurbtitle,blurburl,blurbdesc)
    values
    (#form.ctsrc#,#blurbtitle#,#blurburl#,#blurbdesc#)
    </CFLOOP>

    Loony2nz Guest

  4. #3

    Default Re: Iterative Insert with Variable Field Name

    If each set of form fields (title, url, desc, source) is consecutively named,
    just store the total number of sets in a hidden form field and on the action
    page use a CFLOOP to insert the values of each set



    <!--- psuedo code ... --->
    <cfloop from="1" to="#form.numberOfSets#" index="i">
    <cfquery ...>
    INSERT INTO blurbs (source, blurbtitle,blurburl, blurbdesc)
    VALUES (#form["blurb"& i &"source"]# , #form["blurb"& i &"title"]#,
    #form["blurb"& i &"url"]#, #form["blurb"& i &"desc"]#)
    </cfquery>
    </cfloop>

    mxstu Guest

  5. #4

    Default Re: Iterative Insert with Variable Field Name

    You don't really even need the temp variables, just perform the evaluation within the query statement.
    mxstu Guest

  6. #5

    Default Re: Iterative Insert with Variable Field Name

    Evaluating in the query statement would work just the same.
    But, i think for legibility for myself and other co-workers setting a temp
    variable is cleaner to read.
    Just my 2 cents.

    But thanx for your input!! :)


    Loony2nz Guest

  7. #6

    Default Re: Iterative Insert with Variable Field Name

    Nothing wrong with that. If I'm dealing with long names or more than 4 items, I agree the temp variables are no longer optional .. if you want to be able to read the code ;-)
    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139