Forums

ASP

This topic is locked

Splitting field values

Posted 31 Jul 2001 17:25:52
1
has voted
31 Jul 2001 17:25:52 Bec C posted:
I am using the following code to split a field into separate values. The field is used as a search.

On submitting a form the user jumps to a new page with this code on it:

<%
fieldSplit = rsResults.Fields.Item("keywords".Value
newStr = Split(fieldSplit, ",", -1, 1)
max = UBound(newStr)

for i = 0 to max
if newStr(i) = request.querystring("keywords" then response.write ("<br>" & newStr(i))
next
'Move to next record required

%>

As it stands the page only displays the response.write bit if I happen to type the first value of the keyword field into the search form e.g.

Keyword field = graphics, database, asp, flash

If I submit graphics as a search the response.write bit works but if I type in database, asp or Flash it does not work. If I re-order the keyword field values then it is then the first record in the list that I can search and display.

What is wrong here?

Also how do I jump to the next record in my recordset so that I check all records in a database table and not just record one?

Replies

Replied 31 Jul 2001 19:15:32
31 Jul 2001 19:15:32 Joel Martinez replied:
ahh, I think that your problem may lie in whitespaces after the comma... if the values you're checking against are exactly as you typed them then I"m pretty sure this is it...

if you split this string "a, b, c" the the first one will be "a", but the second one will be " b". so a comparison of " b" = "b" will not work.

also, moving from record to record is accomplished by using the rsname.movenext method

Joel Martinez

----------
Is this thing on?....
Replied 31 Jul 2001 23:12:24
31 Jul 2001 23:12:24 Bec C replied:
Yes it was the whitespace in the end!

I get a while/wend loop thingy working to go through the records.

Thanks anyway!

Reply to this topic