Ask a Question related to Coldfusion Database Access, Design and Development.
-
Loony2nz #1
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
-
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... -
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... -
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,... -
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... -
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... -
Loony2nz #2
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
-
mxstu #3
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
-
mxstu #4
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
-
Loony2nz #5
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
-
mxstu #6
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



Reply With Quote

