| Author |
Topic Search Topic Options
|
faubo
Senior Member
Joined: 30 May 2002
Location: Brazil
Status: Offline
Points: 560
|
Post Options
Thanks(0)
Quote Reply
Topic: spliting the data in a field Posted: 16 February 2003 at 10:43pm |
Ok,
I have a field with keywords separated with comas.
I want to make links with each of these words in the strings, how can I separate them and do this?
Example:
Keywords: biodiversity, climate change, policy, ozone
I want links like that:
search.asp?biodiversity
search.asp?climate change
search.asp?policy
search.asp?ozone
I want to put that in my news app (a modified version of the old news app from here), so people can search directly in my DB from subjects close to the ones present in the news they just read.
But I have no idea how I can separate these... I and don't want to create a lot of keywords fields... is that possible?
Thanks again people!
Edited by faubo
|
|
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
Posted: 17 February 2003 at 12:05am |
Something like: <% thisstring = xxxxxxxx 'Whatever your comma seperated string is thisarray = Split(Trim(thisstring), ",") For i = LBound(thisarray) To UBound(thisarray) Response.Write <a href="search.asp?search=" & thisarray(i) & "">" & thisarray(i) & "</a>" "<br>" Next %>
OK, I am pretty tired so check I got the quotes right....should work for you though
|
 |
faubo
Senior Member
Joined: 30 May 2002
Location: Brazil
Status: Offline
Points: 560
|
Post Options
Thanks(0)
Quote Reply
Posted: 17 February 2003 at 10:25pm |
Thanks Michael, I will try that,
I got the idea, if didn't work I will mess around and find the right way
|
|
|
 |
faubo
Senior Member
Joined: 30 May 2002
Location: Brazil
Status: Offline
Points: 560
|
Post Options
Thanks(0)
Quote Reply
Posted: 24 February 2003 at 1:07am |
Ok, I almost made it.
Everything is working as they should, the only problem is when I have a keyword that are more than one actually, like "Climate Change" the link for this keywork is with only the first word in the string, it's only .asp?Climate in this example.
Is there any way to solve this?
Thanks again.
btw, here is the code with the correct quotes:
<% thisstring = rsNews("pchave") thisarray = Split(Trim(thisstring), ", ") For i = LBound(thisarray) To UBound(thisarray) Response.Write"<a href=procura.asp?" & thisarray(i) & ">" & thisarray(i) & "</a> <br>" Next %>
|
|
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
Posted: 24 February 2003 at 2:36am |
Michael has split using the comma as delimter, so any 2 word phrases would still be in the array. I assume its being left off due to being put into the querystring without encoding.
Try urlEncoding() the value thisarray(i) as you build the link and it should work.
Cheers, A
Edited by Bunce
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |
MorningZ
Senior Member
Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
|
Post Options
Thanks(0)
Quote Reply
Posted: 24 February 2003 at 10:45am |
|
Full code:
<%
thisstring = rsNews("pchave")
For each item in Split(Trim(thisstring), ",")
Response.Write"<a href=""procura.asp?" & Server.URLEncode(trim(item)) & """>" & item & "</a>
"
Next
%>
notice it just splits on "," instead of ", " just in case there aren't spaces around, the trim() inside the loop will take care of white space
Edited by MorningZ
|
|
Contribute to the working anarchy we fondly call the Internet
|
 |
faubo
Senior Member
Joined: 30 May 2002
Location: Brazil
Status: Offline
Points: 560
|
Post Options
Thanks(0)
Quote Reply
Posted: 24 February 2003 at 1:25pm |
Ok, just spent one hour trying to make URLEncode to work, I read Bunce Post before MorningZ write his.

Anyway, thanks guys! The code is working, bu I'm still having a problem,
the URLEncode is making my composite keywords Like this "Climate+Change"
Shouldn't be "Climate%20Change"?
My search page is a very bad one, I think I will hold on all of this and learn how to do it right, I will take a closer look in Borg's Internet Search Engine.
But now I have my real work to do, see you later.
|
|
|
 |
MorningZ
Senior Member
Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
|
Post Options
Thanks(0)
Quote Reply
Posted: 24 February 2003 at 2:02pm |
faubo wrote:
the URLEncode is making my composite keywords Like this "Climate+Change"
|
when you read and display the data, it'll "unencode it" automatically....
as an example... check out this link (copy an paste it into the address line on a browser
http://www.team-integra.net/index.asp?PageMsg=Hello+there+faubo
|
|
Contribute to the working anarchy we fondly call the Internet
|
 |