Skip to main content
Participant
Jan 4, 2013 12:45 AM UTC
Question

Update several data simultaneously in a database

Hello all,

Who can help me on this : I am trying to update simultaneously all data returned with a simple cfoutput query, where all form tags are indexed with all the id(s) returned by the query (same serie of input/textarea/etc. for each id, but only one single validation button for all id). I am stuck and cannot find a way to do this. Would someone have a simple example of how I could proceed ? That would save my life...

Thanks

Jean

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

Inspiring
Jan 4, 2013 3:06 AM UTC

Your question is unclear.

It might mean that you are generating form fields from a query, but it might mean something else.  The comment about single validation button may or may not be relevent.

Perhaps if you could provide more details.

Translate
Participant
Jan 4, 2013 8:13 AM UTC

Let me try to be more explicit:

I will for example create a simple query such as :

<cfquery datasource="ABC" name="DEF"

select book_id, book_name from books

</cfquery>

Then I create the following form:

<form....>

<cfoutput query="DEF">

#book_id# <input type="text" name="book_#book_id# value="#book_name#><br>

</cfoutput>

<input type="submit" value="Refresh">

</form>

I want to be able to update all the "#book_name#" simultaneously but as I cannot nest a cfquery and insert inside a cfoutput, I need to go through a different path...and I don't know how. An example would be helpful.

If you can solve this for me, I would be really grateful !

Jean

Translate
BKBK
Community Expert
Community Expert
Jan 4, 2013 9:19 AM UTC

<cfif isDefined("form.sbmt")>

    <cfoutput query="session.DEF">

        <!--- Update only book names that were changed in the form--->

        <cfif book_name is not form["book_#book_id#"]>

            <cfquery datasource="ABC" name="session.DEF">

                update books

                set book_name = '#form["book_#book_id#"]#'

                where book_id = #book_id#

            </cfquery>

        </cfif>

    </cfoutput>

</cfif>

<!--- Store query in session scope. This makes it dynamically updatable, and available to the update queries above as well as to the form below --->

<cfquery datasource="ABC" name="session.DEF">

select book_id, book_name from books

</cfquery>

<!--- In this test, the form submits to its own page--->

<cfform>

<cfoutput query="session.DEF">

#book_id# <cfinput type="text" name="book_#book_id#" value="#book_name#"><br>

</cfoutput>

    <cfinput name="sbmt" type="submit" value="Refresh">

</cfform>

Translate