User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 374,181 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,418 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser:
Views: 848 | Replies: 2
Reply
Join Date: Mar 2008
Posts: 2
Reputation: onetwothree is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
onetwothree onetwothree is offline Offline
Newbie Poster

Help coldfusion - save edited query results

  #1  
Mar 15th, 2008
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Downingtown
Posts: 45
Reputation: hinde is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
hinde hinde is offline Offline
Light Poster

Tutorial Re: coldfusion - save edited query results

  #2  
Mar 16th, 2008
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).
Last edited by hinde : Mar 16th, 2008 at 10:18 pm. Reason: Edited to add quoted around what are almost certainly form fields containing text. I swear to god that gets me every damn time.
Reply With Quote  
Join Date: Mar 2008
Posts: 2
Reputation: onetwothree is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
onetwothree onetwothree is offline Offline
Newbie Poster

Re: coldfusion - save edited query results

  #3  
Mar 17th, 2008
thank you very much for your help - i will try and apply what you have suggested.

very much appreciated.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ColdFusion Marketplace
Thread Tools Display Modes

Other Threads in the ColdFusion Forum

All times are GMT -4. The time now is 4:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC