Solved

stop duplicate prodIDs being added to to listPrepend

Posted on 2010-11-30
6
331 Views
Last Modified: 2012-06-27
hi all,

i'm using this:
<cfparam name="client.recentlyViewed" default="">
<cfset viewString = url.prodID & "|" & rsgetProduct.product_Name & "|" & request.scndcatName>
<cfset client.recentlyViewed = listPrepend(client.recentlyViewed, viewString)>

to store recently viewed products on my site in the client side cookie.

i then display the recently viewed products to the customer on another page.

the prodID is always unique. how can i stop duplicate prodIDs being added to the 'client' so i downt output dupes?

thanks
0
Comment
Question by:bede123
  • 3
  • 3
6 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 34240679
If you mean the whole "viewString", use listFindNoCase to determine if the item exists in the list first.

<!--- append it only if it doesn't already exist ....--->
<cfif NOT listFindNoCase(client.recentlyViewed, viewString)>
    <cfset client.recentlyViewed = listPrepend(client.recentlyViewed, viewString)>
</cfif>

rsgetProduct.product_Name & "|" & request.scndcatName

Do any of those values contain contain commas? The list delimiter should never exist in the values you're appending.
0
 
LVL 1

Author Comment

by:bede123
ID: 34241994
ok thanks let me try this.

>Do any of those values contain contain commas? The list delimiter should never exist in the values you're appending.

its possible they contain commas but unlikely. is this a problem?
0
 
LVL 1

Author Closing Comment

by:bede123
ID: 34242163
perfecto! worked perfectly thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 52

Expert Comment

by:_agx_
ID: 34242301
its possible they contain commas but unlikely. is this a problem?

Delimiters should never appear in the data or list functions wont' work as you expect.   For example ListLen() would tell you this string has 2 elements:

    "a|prodName1|catName1,b|prodName2|catName2"

But put a comma in the first product name and it will think it's got 3. So a ListFindNoCase() wouldn't return the right results either ..

    "a|prod,Name1|catName1,b|prodName2|catName2"
0
 
LVL 1

Author Comment

by:bede123
ID: 34242546
hmm ok thanks. thats worth knowing. not sure what i can do about it though as i dont create the prod names i only collect them from a db.

many thanks
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34243233
Use a different list delimiter.  Anything not used in the data should work.  
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now