I am trying to build a 'Recently Viewed' feature for an ecommerce site to
display thumbnail images and product names with links on them in the reverse
order that customers click on them; in other words, the product they last
viewed should appear at the top of the list. I am having problems using either
a Structure or Array to do this, although either should work. But neither
seems to work according to the documentation and I am stymied. Here is how it
might work, if it did work, using arrays.
Every time a customer lands on a new Product page the ProductID of the product
is appended to a list in a cookie named RECENTLYVIEWED, so that
COOKIE.RECENTLYREVIEWED might have a value something like
"647,73,123,621,733,818,290" from oldest to newest product viewed
All the product data are in a cached query named AllProducts so that numerous
subqueries like this one RecentlyViewed to get the rest of the data do not
require another hit to the database:
<CFQUERY dbType="Query" NAME="RecentlyViewed">
SELECT
ProductID,
ProductName,
ThumbNail
FROM AllProducts
WHERE ProductID IN (#COOKIE.RECENTLYVIEWED#)
</CFQUERY>
Unfortunately the query doesn't output the records in the same order specified
in the IN clause or it would be too easy; consequently the data have to be put
into the correct order somehow. Logically I would first initialize three
arrays:
<CFSET AryProductID = ArrayNew(1)>
<CFSET AryProductName = ArrayNew(1)>
<CFSET AryThumbNail = ArrayNew(1)>
Then loop over the output of the RecentlyViewed query to set an array like
this: (except it doesn't work)
<CFLOOP INDEX="hh" FROM="1" TO="#RecentlyViewed.RecordCount#">
<CFSET AryProductID[RecentlyViewed.ProductID#] =
"#RecentlyViewed.ProductID[hh]#">
<CFSET AryProductName[RecentlyViewed.ProductID] =
"#RecentlyViewed.ProductName[hh]#">
<CFSET AryThumbNail[RecentlyViewed.ProductID] =
"#RecentlyViewed.ThumbNail[hh]#">
</CFLOOP>
This SHOULD produce an array with values like so: (except it doesn't work)
AryProductID[647] = 647
AryProductName[647] = 'Lemon Cake'
AryThumbNail[647] = 'LemonCake.jpg'
AryProductID[73] = 73
AryProductName[73] = 'Cranberry Muffins'
AryThumbNail[73] = 'CranMuffins.jpg'
AryProductID[123] = 123
AryProductName[123] = 'Blueberry Muffins'
AryThumbNail[123] = 'BlueMuffins.jpg'
....etc.
With arrays coded by the ProductID I should be able to use the
COOKIE.RECENTLYVIEWED list of ProductIDs to output everything in its proper
order like so by the use of Reverse(COOKIE.RECENTLYVIEWED): (except it doesn't
work)
<CFOUTPUT>
<CFLOOP INDEX="ii" LIST="#Reverse(COOKIE.RECENTLYVIEWED)#">
#AryProductID[ii]# (using the ProductID to construct a dynamic URL to the
product, I know it's redundant and unnecessary in this particular case but it's
just for illustration)
#AryProductName[ii]# (to display the product name on the customer's
Recently Viewed list)
#AryThumbNail[ii]# (to display the product image with the product name on
the customer's Recently Viewed list
</CFLOOP>
</CFOUTPUT>
I don't care if I have to use Arrays, Structures, or anything else to get the
data displayed the way I want, this is just an example of one way it might be
done if ColdFusion actually worked the way it is documented to work.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315923
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4