Solved

stop duplicate prodIDs being added to to listPrepend

Posted on 2010-11-30
6
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

630 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