Solved

stop duplicate prodIDs being added to to listPrepend

Posted on 2010-11-30
6
338 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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