Apologies if this is a really basic question, but i am quite new to coldfusion.

I have a database where i have some stored standard data in.

i can search this database for the data I want, (eg 10 specific records of data), and output it to a form with a query. This is all fine.

What i can't work out is how i then get the data which has been output to a form, (and possibly edited by the user), inserted into a different database table, (i know how to insert data into a database table from a form where i have a specific field for every item of data - but as i am outputting a query here into a form with variable number of record results - the individual fields in the form don't have a name as when i have a set form where i know the number of fields etc)?

Anyway, not sure if the above makes much sense, but any ideas to point me off in the direction i need to go would be very appreciated, and would no doubt save me a huge amount of time!

thanks.

Recommended Answers

All 2 Replies

Please post what you have so far, and I will take a look at it.

Regardless, I have some tips for you. From what I gather from your original post, you are trying to retrieve and present a variable number of records in forms that allow for a user to modify the data. In the past, when I have to deal with issues like this, I will usually have one cfoutput tag that loops over the records your query returned, with a hidden field that is outside the cfoutput containing the ids of the records in a comma-delimited format (name it queryIDs). The loop will present the data in a form as you have already said you are able to do, and you will simply have the names of the field contain the unique identifier of the record (eg. firstName_#qryMyQuery.uniqueID#). On the action page of the form you will use a cfloop to loop over the list of ids from your hidden field on the form page. Inside the loop you will then perform the database action you need to perform. You can see what I mean below:

<cfloop list="#FORM.queryIDs#" index="recordID">
    <cfquery name="INSERT" datasource="myDatasource">
    Insert Into Table2 (Table2ID, Table1ID, FirstName, LastName, ...)
    Values (#newRecordID#,
        #recordID#
        '#Evaluate("FORM.FirstName_#recordID#")#',
        '#Evaluate("FORM.LastName_#recordID#")#',
        ...)
    </cfquery>
</cfloop>

You will of course need to determine the value of newRecordID on your own. What makes this possible is the Evaluate Function (read up on it at Adobe's Livedocs). The evaluate function receives a string and dynamically returns the value of the string. In this case you are asking it to return the value of FORM.FirstName_1 (or whatever the value of recordID is).

Note: One thing that you should be aware of is that you should never start the name of a form field with a number. It tends to not work (at least it didn't work the last time I tried it).

thank you very much for your help - i will try and apply what you have suggested.

very much appreciated. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.