INSERT INTO blurbs (source, blurbtitle,blurburl, blurbdesc) VALUES (#form["blurb"& i &"source"]# , #form["blurb"& i &"title"]#, #form["blurb"& i &"url"]#, #form["blurb"& i &"desc"]#) [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => mxstu [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Iterative Insert with Variable Field Name - Coldfusion Database Access

Iterative Insert with Variable Field Name - Coldfusion Database Access

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;...

  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. #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

  3. #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

  4. #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

  5. #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

  6. #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

Similar Threads

  1. Insert ASP variable into SQL table
    By Mintyman in forum Dreamweaver AppDev
    Replies: 4
    Last Post: April 1st, 09:39 AM
  2. insert anchor # into cf variable string
    By oak3 in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: March 25th, 05:34 PM
  3. Read and insert to MySQL a URL-Variable
    By zack in forum PHP Development
    Replies: 1
    Last Post: October 15th, 08:25 AM
  4. Insert TAB into calculated field
    By Don in forum FileMaker
    Replies: 3
    Last Post: August 11th, 07:30 AM
  5. Insert a file in a SQL field
    By Jacco Schalkwijk in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 3rd, 09:57 AM

Bookmarks

Posting Permissions

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