Skip to main content
Known Participant
February 16, 2010
Question

How to edit a list ?

  • February 16, 2010
  • 2 replies
  • 352 views

I have a column in my sql table that is basically a list. For example, it might contain 12345,67890.98766,76124,97374. etc...

What is the best way to edit this list ?

If I just have <cfinput type="text" name="variableList" value="#qry.variableList#">, it will display it like above (which could be quite long) and I would just have to go to the values that I would like to edit. But this is not a good approach.

How can I set it up so that each individual value (comma separted) is in its own display field (one on top of the other to conserve space) and how will the list be updated with the changes.

For example, my display would be :

12345

67890

98766

76124

97374

If I change the second one only, from 67890 to 09876, how does that particular value get updated only, and the rest remain the same ?

Is this even possible ? If not, what would be the best way to do this ?

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
February 20, 2010

Olivia Crazy Horse wrote:

I have a column in my sql table that is basically a list. For example, it might contain 12345,67890.98766,76124,97374. etc...

What is the best way to edit this list ?

If I just have <cfinput type="text" name="variableList" value="#qry.variableList#">, it will display it like above (which could be quite long) and I would just have to go to the values that I would like to edit. But this is not a good approach.

How can I set it up so that each individual value (comma separted) is in its own display field (one on top of the other to conserve space) and how will the list be updated with the changes.

For example, my display would be :

12345

67890

98766

76124

97374

If I change the second one only, from 67890 to 09876, how does that particular value get updated only, and the rest remain the same ?

Is this even possible ? If not, what would be the best way to do this ?

Yes, it is possible. Here follows one way to do it.

<cfif isdefined("form.IDList")>
    Edited list (comma-delimited, since the form fields share same name):<br>
    <cfoutput>#form.IDList#</cfoutput>
   
    <!--- update table with edited list --->
    <!--- <cfquery name="editListColumn" datasource="myDSN">
        update myTable
        set listColumnName = '#form.IDList#'
        where primaryKeyName = #primary_key_value_corresponding_to_row#
    </cfquery> --->
<cfelse>

<!--- value coming from a row in the database --->
<cfset qry.variableList="12345,67890,98766,76124,97374">

<cfform>
<!--- separate list elements into individual editable form fields  --->
<cfloop list="#qry.variableList#" index="listItem">
    id: <cfinput name="IDList" type="text" value="#listItem#"><br>   
</cfloop>
<cfinput name="sbmt" type="submit" value="edit">
</cfform>

</cfif>

ilssac
Inspiring
February 17, 2010

The best way to edit this is to NOT store lists in a database field.

99.68723% of the time that one sees a list in a database field, it is a sign that the database design needs to be normalized and a related table created to store the list values in individual records.

Until such a time, the only way to edit these values is to replace the entire list.  So you will have to build a new list from your form inputs and then use this new list to replace the entire list currently in the record.