Try listFind() instead.  If that doesn't work you'll need to do a list loop
to directly compare the values.  It should work though.  I believe that
listContains will find sub-strings, which would mean that's expected
behavior.

You should really be doing this with a link table that contains the id of
the item, and then the color id.  Shouldn't store lists in a field.

Also so you know CF Studio and Dreamweaver both contain excellent CFML
documentation.  You can look up functions by type (in this case list)

Tim
  -----Original Message-----
  From: Cutter (CF-Talk) [mailto:[EMAIL PROTECTED]
  Sent: Saturday, January 03, 2004 9:56 PM
  To: CF-Talk
  Subject: Match to list item

  I've got a table that stores details about apparel items. One of these
  fields contains a list of numbers. These numbers correspond to the IDs
  of various colors in a different table (Example: tblItem.txtColors for
  specific ID = 1,3,4,7 = Black,Green,Yellow,Brown).

  I have an editor which easily inputs each item into my database. I use a
  multiselect box to pick my colors (the options are drawn from the colors
  table and listed alphabetically). My issue comes with my form to edit
  existing entries.

  The edit form looks almost exactly like the add form with the values of
  the record already showing in the respective input boxes. Sort of. I'm
  probably doing this wrong, but I populate my multiselect options with a
  query of the colors table:

  <cfquery name="qColor" datasource="#variables.DSN#">
  select intBoutColorID as ID,
  txtColor as Color
  from tblBoutColor2
  order by txtColor
  </cfquery>

  But then I need to select the colors that are already on record for that
  item. Since the value in the field looks like a list (1,3,7,9) I looked
  for a function to find a value in a list. I thought I could use
  listcontains, but ran into a small issue:

  <select name="color" class="boxes" multiple size="5">
  <option value=""<cfif qItem.Colors lt 1> selected</cfif>>- No Color
  Needed -</option>
  <cfoutput query="qColor">
  <option value="#qColor.ID#"<cfif
  listcontains(qItem.Colors,qColor.ID,",") gt 0>
  selected</cfif>>#qColor.Color#</option>
  </cfoutput>
  </select>

  Even though I identified the delimiter (although a comma is the default)
  it still gives me a small problem with the IDs. If my value list is
  (23,24 = Tan, Grey) then it actually selects 2,3,4,23,24 (that's a few
  extra colors the item doesn't come in). I can't seem to get an exact
  match for the list items.

  Should I be using a different function? Is there a better, easier way to
  accomplish this? Any help is greatly appreciated.

  Cutter
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to