Skip to main content
Inspiring
March 7, 2008
Question

How to edit multiple records

  • March 7, 2008
  • 2 replies
  • 454 views
I query a table using ref_no and return five records. I display all five records in form format, in a table, using <cfoutput query="qry">.

This is an edit page, so what I need to do for each line item is allow the user to edit. I am thinking of adding two radio buttons next to each record. So if they want to delete this line item, they would check the delete button and if they want to change it, they would check the edit button.

If I have this for each line item, my question is how do I handle the multiple line items when I submit, would it be a cfloop ?

Also, if they want to add a new line item, I guess there can be a third button called add, but how would that be handle also ?

Anybody have a nice technique/code to do this ?
    This topic has been closed for replies.

    2 replies

    Inspiring
    March 7, 2008
    For the deletions, checkboxes, all named the same would be a lot simpler. Then you just get a list of items to delete.

    For the edits, I would simply append the record id to the name of the input name so you know which one is which.

    For new records, just put another textbox at the end.
    March 7, 2008
    Your description of the solution to the problem is right on. A table, with the first two columns "Edit" and "Delete" with radio buttons, followed by a description of the item. The trick is for the action page to be able to know which radio buttons were clicked on the form.

    One way to do this is to make the name/value of the Edit radio button NAME="edit VALUE="#itemId#" and the Delete radio button NAME="delete" VALUE="#itemId#", where itemId is the unique identifier, from the database, for each item.

    On your action page, you need to guard against no radio buttons being checked, so at the start of the page, do the folowing:
    <CFPARAM NAME="edit" DEFAULT="">
    <CFPARAM NAME="delete" DEFAULT="">

    Then you can process the edit and/or delete using the itemId in the CFQUERY WHERE clause.

    If you want to add a new item, a button or check box for that purpose can be provided.
    trojnfnAuthor
    Inspiring
    March 7, 2008
    Thanks jdeline, I will give your method a try, hopefully it will work for me.

    so my unique identifer is ref_no, so I would have :
    <input type="radio" name="edit" value="#iref_no#> Edit <br>
    <input type="radio" name="delete" value="#ref_no#"> Delete

    When I submit to the action page, and there are five line items for the ref_no, how will it know to go thru each one, would I still use the cfloop ?

    In the query, the where clause is where ref_no = '#ref_no#', but do I still need cfif to determine if it is edit or delete ?

    I guess I am still a little confused on the processing.
    March 8, 2008
    Since my example (and yours) uses radio buttons, at the most you will receive one ref_no for edit and one ref_no for delete. By using the <CFPARAM> at the top of your action page, you will have either a ref_number for edit and/or delete, or a FALSE. For example, the <CFIF NOT edit> statement, if TRUE, says that no edit button was checked.

    Dan suggests check boxes for the delete - in that case, if multiple check boxes are checked, you will receive the a comma delimited list of ref_no. So you would do something like the following:
    <CFQUERY NAME="deleteRecords" ... >
    DELETE FROM myTable WHERE ref_no IN (#FORM.delete#)
    </CFQUERY>