Forum Moderators: open

Message Too Old, No Replies

Extract Cookie Info - Insert into DB

         

powerslave

11:42 am on Apr 20, 2005 (gmt 0)

10+ Year Member



Hello

I need to extract information from a cookie string from a shopping cart. It just adds all the information on the end of the string, i need to extract the 5 details from it, and repeat the process over again for the next product sold

the cookie will look something like this for 3 products sold, seperated by a ¦ at the moment

.[DiningCard¦35¦102¦1¦1][EntertainmentCard¦35¦101¦1¦1][LivingCard¦35¦103¦1¦1]

SO i need it to search for a seperater key and pull out information from there and save into variables...i am not good with VB so would like to see how you do this in a For Loop or whatever , i dont know to figure out length of a cookie in VB and how to search for "¦" and seperate it etc....well maybe you understand my situation :)

Thanks for your help :)

Easy_Coder

3:02 pm on Apr 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So is the . an indicator of a new line item and the ¦ acts as a seperator for each item in the line? Is that right?

powerslave

11:02 am on Apr 21, 2005 (gmt 0)

10+ Year Member



the . will be the start of the cookie, the brackets [ ] are the start and end of a product sold.
If u just mentioned the code that takes out the ¦ meaning different sale information (like price, quantity, code number) that can be put into a variable and then the DB i could probably figure the rest from that example

the cookie is made in Javascript using a cart that does not save to the database so i need to figure out how to do that :)

Thanx

[edited by: powerslave at 11:05 am (utc) on April 21, 2005]

powerslave

11:03 am on Apr 21, 2005 (gmt 0)

10+ Year Member



...

Easy_Coder

9:08 pm on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this and tell me if it unwinds that way you envisioned:

<%
sTempBuff = "[DiningCard¦35¦102¦1¦1][EntertainmentCard¦35¦101¦1¦1][LivingCard¦35¦103¦1¦1]"
vTempArr = Split(sTempBuff, "[")
' Clean inner loop items
Function c(in_string)
If InStr(1, in_string, "]") <> 0 Then
retVal = Replace(in_String, "]", "")
Else
retVal = in_string
End If
c = retVal
End Function
'Clean outer loop base item
Function o(in_string)
pipePos = Instr(1,in_string, "¦")
If pipePos <> 0 Then
retVal = left(in_String, pipePos - 1)
Else
retVal = in_string
End If
o = retVal
End Function
For x = 1 To ubound(vTempArr)
Response.Write o(vTempArr(x)) & "<br>"
sInnerTemp = Split(vTempArr(x), "¦")
for y = 1 to ubound(sInnerTemp)
Response.Write c(sInnerTemp(y)) & "<br>"
next
Response.Write "<br><br>"
Next
%>

powerslave

10:50 am on Apr 22, 2005 (gmt 0)

10+ Year Member



Thanx for ya help mate :)

I havent tried it yet because i found it some theory on VB and used that

ive got it work up until trying to figure out the length of an array

could u please give me some code to tell me the size of an array? the array of the cookie I splitted....

So then i can know when to stop my loop that inserts into the Database

I suspect it has somthing to do with the
For x = 1 To ubound(vTempArr)

line u have there....ill play around with it but if u could help that would be good :)

Thanks :)

Easy_Coder

12:26 pm on Apr 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ubound() returns the top end of the array

That why I looped to --> ubound(vTempArr)

You could loop like this so that it's dynamic...

for x = lbound(vTempArr) to ubound(vTempArr)

So, that's lower bound to upper bound.

Sounds like you're on your way.