I can't actually figure out what you're getting stuck on... actually re-reading
your examples ... well, I'm afraid they look like nonsense.
So, I figured I'd write a simple Recently Viewed component, which should give
you what you need to get all this working. :)
It's NOT perfect code (and is entirely untested), but should at least give you
a base to work from.
To use it, do this:
---
<cfif NOT StructKeyExists(Session,'RecentlyViewed')>
<cfset Session.RecentlyViewed =
createObject("component","recently_viewed.cfc").init(MaxItems=10) />
</cfif>
<cfset Session.RecentlyViewed.add(647) />
<cfset Session.RecentlyViewed.add(73) />
<cfset Session.RecentlyViewed.add(123) />
<cfdump var="#Session.RecentlyViewed.read('list')#"/>
<cfdump var="#Session.RecentlyViewed.read('array')#"/>
<cfdump var="#Session.RecentlyViewed.read('struct')#"/>
<cfdump var="#Session.RecentlyViewed.read('query')#"/>
---
And the actual recently_viewed.cfc code is this:
---
<cfcomponent output="false">
<cffunction name="init" returntype="recentlyviewed" output="false"
access="public">
<cfargument name="MaxItems" type="Numeric" default="10"
hint="Maximum number of items allowed in the list."
/>
<cfset Variables.RecentlyViewed = ""/>
<cfset This.MaxItems = Arguments.MaxItems />
<cfreturn This/>
</cffunction>
<cffunction name="add" returntype="void" output="false" access="public"
hint="Add a new item to front of the recently viewed list"
>
<cfargument name="Id" type="Numeric"/>
<cfset Variables.RecentlyViewed =
ListAppend(Variables.RecentlyViewed,Arguments.Id)/>
<cfif ListLen(Variables.RecentlyViewed) GT This.MaxItems>
<cfset Variables.RecentlyViewed =
ListRest(Variables.RecentlyViewed)/>
</cfif>
</cffunction>
<cffunction name="remove" returntype="void" output="false"
access="public"
hint="Removes a specific Id from the recently viewed list,
regardless of ordering."
>
<cfargument name="Id" type="Numeric"/>
<cfset Variables.RecentlyViewed =
rereplace(Variables.RecentlyViewed,'\b#Arguments.Id#\b','')/>
</cffunction>
<cffunction name="read" returntype="any" output="false" access="public"
hint="Provides the recently viewed items in output format of
choice"
>
<cfargument name="Format" type="String" default="array"
hint="list|array|struct|query"/>
<cfset var Result = 0 />
<cfset var id = 0/>
<cfset var info = 0/>
<cfset var CurRow = 0/>
<cfif Arguments.Format EQ 'list'>
<cfset Result = Variables.RecentlyViewed />
<cfelseif ListFind('array,struct,query',Arguments.Format)>
<cfswitch expression="#Arguments.format#">
<cfcase value="array">
<cfset Result = ArrayNew(1)/>
</cfcase>
<cfcase value="struct">
<cfset Result = StructNew()/>
</cfcase>
<cfcase value="query">
<cfset Result =
QueryNew("ProductId,ProductName,Thumbnail")/>
</cfcase>
</cfswitch>
<cfloop index="id"
from="#ListLen(Variables.RecentlyViewed)#" to="1" step="-1">
<cfset info = readItemInto(id)/>
<cfswitch expression="#Arguments.format#">
<cfcase value="array">
<cfset ArrayAppend( Result ,
info )/>
</cfcase>
<cfcase value="struct">
<cfset Result[id] = info />
</cfcase>
<cfcase value="query">
<cfset CurRow =
QueryAddRow(Result)/>
<cfset Result.ProductId[CurRow]
= info.ProductId />
<cfset
Result.ProductName[CurRow] = info.ProductName />
<cfset Result.Thumbnail[CurRow]
= info.Thumbnail />
</cfcase>
</cfswitch>
</cfloop>
<cfelse>
<cfthrow message="Invalid Format '#Arguments.Format#'.
Use list|array|struct|query" />
</cfif>
<cfreturn Result/>
</cffunction>
<cffunction name="readItemInfo" returntype="Struct" output="false"
access="private">
<cfargument name="Id" type="Numeric"/>
<cfset var qryInfo = 0/>
<cfset var Result = StructNew()/>
<cfquery name="qryInfo" datasource="#Application.Datasource#">
SELECT ProductID , ProductName , ThumbNail
FROM AllProducts
WHERE ProductID = <cfqueryparam value="#Arguments.Id#"
type="cf_sql_integer"/>
</cfquery>
<cfset Result.ProductId = qryInfo.ProductId[1] />
<cfset Result.ProductName = qryInfo.ProductName[1] />
<cfset Result.Thumbnail = qryInfo.ThumbNail[1] />
<cfreturn Result />
</cffunction>
</cfcomponent>
---
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:315962
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4