Solved

stop duplicate prodIDs being added to to listPrepend

Posted on 2010-11-30
6
339 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
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?
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

739 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