Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

stop duplicate prodIDs being added to to listPrepend

Posted on 2010-11-30
6
Medium Priority
?
346 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 2000 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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
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

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

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 …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

715 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