Skip to main content
Participant
January 4, 2013
Question

Update several data simultaneously in a database

  • January 4, 2013
  • 1 reply
  • 1053 views

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 has been closed for replies.

1 reply

Inspiring
January 4, 2013

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.

Participant
January 4, 2013

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

BKBK
Community Expert
Community Expert
January 4, 2013

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