January 27, 201115 yr Hi all...... I'm trying to figure out how to use cookies in ASP to captcha a visitors recently viewed products. I want to take the productID from the product detail page and use this to set the cookie dictionary. Then i want to use the dictionary values (productID's) to filter a recordset. Can anyone help? Andy
January 27, 201115 yr Something like... Response.Cookies("productViews") = Request.Cookies("productViews") & "," & productID; SELECT * FROM products WHERE id IN (" & Request.Cookies("productViews") & ") LIMIT 10;
January 31, 201115 yr Author Hi Jock - Thanks for your reply. I've tried to create a Dreamweaver recordset based on the method your kindly supplied and although the runs fine when testing it in DW, i get this error when i run the page. Any ideas? Thanks --error- Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) [Microsoft][ODBC SQL Server Driver] Incorrect syntax near ','.--error-here's my code:[code]<% Response.Cookies("productViews") = Request.Cookies("productViews") & "," & productID; %><%Dim RSRecentViews__MMColParamRSRecentViews__MMColParam = "1"If (Request.Cookies("productViews") <> "") Then RSRecentViews__MMColParam = Request.Cookies("productViews")End If%><%Dim RSRecentViewsDim RSRecentViews_numRowsSet RSRecentViews = Server.CreateObject("ADODB.Recordset")RSRecentViews.ActiveConnection = MM_shoppingcart_STRINGRSRecentViews.Source = "SELECT * FROM dbo.Products WHERE ProductID = " + Replace(RSRecentViews__MMColParam, "'", "''") + ""RSRecentViews.CursorType = 0RSRecentViews.CursorLocation = 2RSRecentViews.LockType = 1RSRecentViews.Open()RSRecentViews_numRows = 0%><%Dim Repeat1__numRowsDim Repeat1__indexRepeat1__numRows = 10Repeat1__index = 0RSRecentViews_numRows = RSRecentViews_numRows + Repeat1__numRows%>[/code] Something like... [code]Response.Cookies("productViews") = Request.Cookies("productViews") & "," & productID;SELECT * FROM products WHERE id IN (" & Request.Cookies("productViews") & ") LIMIT 10;[/code]
January 31, 201115 yr You need to use a WHERE IN clause in your query, then supply it with a comma separated list of id's which it will get from the cookie.
Create an account or sign in to comment