|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Problem only showing swatches if list contains a swatch name
In a product display page I need to show color swatches based on only thoseAlan Bleiweiss 05/06/04 03:20 P <cfsetBurns, John D 05/06/04 03:27 P When I use this code, I get no match results, and doing a dump shows meAlan Bleiweiss 05/06/04 04:48 P I'd remove the .jpgs so your list is just "1,130,130A,130E,2,23,3,30".Burns, John D 05/06/04 05:38 P In a product display page I need to show color swatches based on only those colors a particular product has available, rather than showing all color swatches in my swatch image directory. (Entire code set and table creation code at bottom of this email) EXPLANATION: I have two lists - One is a comma delimited list stored in one field in my database, the field name is "Colors". Example content: 2,23,23E,30,130,130A,130E The other is a list of files in a directory (using CFDIRECTORY to pull the list) Example content: 1.jpg,130.jpg,130A.jpg,130E.jpg,2.jpg,23.jpg,3.jpg,30.jpg I'm lost as to how to run a comparison on the two lists and bring back only those JPG files that match the Colors data field. And here's what I've done to create a table showing the swatches I know this is incorrect but don't know how to run my comparison. <!-------- SWATCH DISPLAY PAGE CODE FOLLOWS -----------> <!-------- QUERY TO GET COLORS for this specific product -----------> <CFQUERY NAME="GetProduct" DATASOURCE="#EComDB#"> SELECT Colors FROM Products WHERE SiteID='#SiteID#' AND ProductUnique = '#PrId#' </CFQUERY> <!---------- CFDIRECTORY TAG to create list of all swatch images ------------> <cfdirectory action = "list" directory = "c:\inetpub\wwwroot\briona\firstavenue\sites\cdusa\shop\ColorCharts\EuropeanNaturals" name = "GetSwatches" filter = "*.jpg"> <!---------- SWATCH TABLE DISPLAY CODE FOLLOWS: ------------> <TABLE BORDER="1"> <CFSET #count# = 1> <CFLOOP QUERY="GetSwatches"> <CFOUTPUT> <CFSET ThisName=#Replace(#Name#,".jpg","","ALL")#> <!---------- COMPARE COLORS DATA FIELD TO THIS SWATCH- THIS IF STATEMENT IS MY PROBLEM, I'M SURE -------------> <CFIF #GetProduct.Colors# CONTAINS #ThisName#> <!--------- START A NEW ROW -----------> <CFIF #COUNT# EQ 1> <TR> </CFIF> <TD ALIGN="CENTER" VALIGN="TOP"><IMG SRC="ColorCharts/EuropeanNaturals/#name#" ALT="#ThisName#"> <BR> <FONT SIZE="1" FACE="Arial,Helvetica">#ThisName# <BR> <INPUT TYPE="Radio" NAME="MyColorChoice" VALUE="#ThisName#"></FONT></TD> <CFSET #COUNT# = #COUNT# +1> <!--------- END TABLE ROW AFTER 8 CELLS -----------> <CFIF #COUNT# GT 8> </TR> <CFSET #COUNT# = 1> </CFIF> </CFIF> </CFOUTPUT> </CFLOOP> </TABLE> <cfset fullList="1.jpg,130.jpg,130A.jpg,130E.jpg,2.jpg,23.jpg,3.jpg,30.jpg"> <cfset thisList="2,23,23E,30,130,130A,130E"> <cfloop list="#thislist#" index="I"> <cfif listFind(fullList,i & ".jpg")> #i# </cfif> </cfloop> Or to make it easier, strip the jpg off the end of the file names in the full list (if you know they are always jpgs and append that where you're outputting #i#. John Burns In a product display page I need to show color swatches based on only those colors a particular product has available, rather than showing all color swatches in my swatch image directory. (Entire code set and table creation code at bottom of this email) EXPLANATION: I have two lists - One is a comma delimited list stored in one field in my database, the field name is "Colors". Example content: 2,23,23E,30,130,130A,130E The other is a list of files in a directory (using CFDIRECTORY to pull the list) Example content: 1.jpg,130.jpg,130A.jpg,130E.jpg,2.jpg,23.jpg,3.jpg,30.jpg I'm lost as to how to run a comparison on the two lists and bring back only those JPG files that match the Colors data field. And here's what I've done to create a table showing the swatches I know this is incorrect but don't know how to run my comparison. <!-------- SWATCH DISPLAY PAGE CODE FOLLOWS -----------> <!-------- QUERY TO GET COLORS for this specific product -----------> <CFQUERY NAME="GetProduct" DATASOURCE="#EComDB#"> SELECT Colors FROM Products WHERE SiteID='#SiteID#' AND ProductUnique = '#PrId#' </CFQUERY> <!---------- CFDIRECTORY TAG to create list of all swatch images ------------> <cfdirectory action = "list" directory = "c:\inetpub\wwwroot\briona\firstavenue\sites\cdusa\shop\ColorCharts\Euro peanNaturals" name = "GetSwatches" filter = "*.jpg"> <!---------- SWATCH TABLE DISPLAY CODE FOLLOWS: ------------> <TABLE BORDER="1"> <CFSET #count# = 1> <CFLOOP QUERY="GetSwatches"> <CFOUTPUT> <CFSET ThisName=#Replace(#Name#,".jpg","","ALL")#> <!---------- COMPARE COLORS DATA FIELD TO THIS SWATCH- THIS IF STATEMENT IS MY PROBLEM, I'M SURE -------------> <CFIF #GetProduct.Colors# CONTAINS #ThisName#> <!--------- START A NEW ROW -----------> <CFIF #COUNT# EQ 1> <TR> </CFIF> <TD ALIGN="CENTER" VALIGN="TOP"><IMG SRC="ColorCharts/EuropeanNaturals/#name#" ALT="#ThisName#"> <BR> <FONT SIZE="1" FACE="Arial,Helvetica">#ThisName# <BR> <INPUT TYPE="Radio" NAME="MyColorChoice" VALUE="#ThisName#"></FONT></TD> <CFSET #COUNT# = #COUNT# +1> <!--------- END TABLE ROW AFTER 8 CELLS -----------> <CFIF #COUNT# GT 8> </TR> <CFSET #COUNT# = 1> </CFIF> </CFIF> </CFOUTPUT> </CFLOOP> </TABLE> When I use this code, I get no match results, and doing a dump shows me that the only list-item in "fullList" is the last item in the original list At 02:25 PM 5/6/04, you wrote: ----- Excess quoted text cut - see Original Post for more ----- I'd remove the .jpgs so your list is just "1,130,130A,130E,2,23,3,30". Then loop over that and do <cfif listFind(fullList,i)> #i#.jpg </cfif> That should do it. My code may not be perfect, you may need to tweak it some but it should get you started. Look at the docs to see how to use listFind() John Burns name When I use this code, I get no match results, and doing a dump shows me that the only list-item in "fullList" is the last item in the original list At 02:25 PM 5/6/04, you wrote: ----- Excess quoted text cut - see Original Post for more ----- the >full list (if you know they are always jpgs and append that where you're >outputting #i#. > >John Burns > >In a product display page I need to show color swatches based on only >those colors a particular product has available, rather than showing all ----- Excess quoted text cut - see Original Post for more ----- o ----- Excess quoted text cut - see Original Post for more ----- 4>Fast >Unsubscribe] [<http://www.houseoffusion.com/signin/>User Settings]
|
May 19, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||