Print Page | Close Window

spliting the data in a field

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=237
Printed Date: 28 March 2026 at 10:23pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: spliting the data in a field
Posted By: faubo
Subject: spliting the data in a field
Date 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!



-------------
http://www.conhecerparaconservar.org - I don't know how to make you click here



Replies:
Posted By: michael
Date 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=&quot;search.asp?search=" & thisarray(i) & "&quot;>" & thisarray(i) & "</a>" "<br>"
Next
%>

OK, I am pretty tired so check I got the quotes right....should work for you though



Posted By: faubo
Date 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



-------------
http://www.conhecerparaconservar.org - I don't know how to make you click here


Posted By: faubo
Date 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
%>



-------------
http://www.conhecerparaconservar.org - I don't know how to make you click here


Posted By: Bunce
Date 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

 



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: MorningZ
Date 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

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: faubo
Date 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.



-------------
http://www.conhecerparaconservar.org - I don't know how to make you click here


Posted By: MorningZ
Date Posted: 24 February 2003 at 2:02pm
Originally posted by faubo 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net