Link to home
Start Free TrialLog in
Avatar of lshane
lshane

asked on

Classic ASP VBScript: How to separate comma-delimited listings into individual, dynamic links.

Classic ASP VBScript
MS Access
DWMX
WIN XP PRO

Hello.  I have created a recordset and one of the fields has a list of comma-delimited values.  How can I separate each of these value into individual links without creating another table for individual records?

The table is:  [Team Members]
The field is: {tm_mentee}

The tm_mentee values would look like:  (202800, 202810, 202820), etc.

Each of these numbers represents a Team Member.

I would like to make them individual links, if that's possible.  Obviously when I just link the initial dynamic content, it lists all of the numbers, but makes all of them one, big link.


Thanks so much,
Shane
Avatar of basicinstinct
basicinstinct
Flag of Australia image

the easiest way is to use the 'split' function to create an array, then loop through the array and create a link within the loop body...

http://www.w3schools.com/vbscript/func_split.asp
Avatar of lshane
lshane

ASKER

Hello, basicinstinct.  Thank you for replying.  I viewed that section from your link, but I'm a little unsure how to implement that with my field.  Here's my recordset:

=============================================================================
<%
Dim rsMenteeList
Dim rsMenteeList_numRows

Set rsMenteeList = Server.CreateObject("ADODB.Recordset")
rsMenteeList.ActiveConnection = MM_connPMDData2_DSN_STRING
rsMenteeList.Source = "SELECT *  FROM team_members  WHERE tm_ID = " + Replace(rsMenteeList__MMColParam, "'", "''") + ""
rsMenteeList.CursorType = 0
rsMenteeList.CursorLocation = 2
rsMenteeList.LockType = 1
rsMenteeList.Open()

rsMenteeList_numRows = 0
%>
=============================================================================

There is a MEMO field in that table called "tm_mentee", and it contains a comma-delimited list, such as the one I posted above.  

On the page where the dynamic content is viewed, I type:  "<a href="#"><%=(rsMenteeList.Fields.Item("tm_mentee").Value)%></a>".

There's not a loop anywhere.  I just want to split out the list in that MEMO field and make them individual links.

Any ideas?

Thanks so much,
Shane
strLinks = split(rsMenteeList.Fields.Item("tm_mentee").Value)
for i = 0 to ubound(strLinks)
    response.write("<a href=""#"">" & strLinks(i) & "</a>")
next
Avatar of lshane

ASKER

Hello, kevp75.  Where would I place this section of code?


Thanks so much,
Shane
replace your existing code:

"<a href="#"><%=(rsMenteeList.Fields.Item("tm_mentee").Value)%></a>".

with kevs function
but it should be this:

dim strLinks
strLinks = split(rsMenteeList.Fields.Item("tm_mentee").Value, ",")
for i = 0 to ubound(strLinks)
    response.write("<a href=""#"">" & strLinks(i) & "</a>")
next
aye....forgot the character to split on....
SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lshane

ASKER

Ok, thank you, but still getting probs.

I replaced my code with the function in this way:
==============================================================
<%dim strLinks
strLinks = split(rsMenteeList.Fields.Item("tm_mentee").Value, ",")
for i = 0 to ubound(strLinks)
    response.write("<a href=""#"">" & trim(strLinks(i)) & "</a>")
next%>
==============================================================

... but my result was:

202802202804202811  

Pretty much what I had.

Am I doing something wrong?

Thanks,
Shane
Avatar of lshane

ASKER

Did my last posting come through?
well just to confirm, when you do this:

<%=(rsMenteeList.Fields.Item("tm_mentee").Value)%>

you get a comma separated list of values right?  can you post the output of that here?
do this:

<%dim strLinks
strLinks = split(rsMenteeList.Fields.Item("tm_mentee").Value, ",")
for i = 0 to ubound(strLinks)
    response.write("<a href=""#"">" & trim(strLinks(i)) & "</a><br />")
next%>
Avatar of lshane

ASKER

Hey, kevp75.  That did it!  Here's the result:

202802
202804
202811

I do have one other piggy-back question for this, but if I need to re-thread, I will.

What I REALLY need to do is send the value of each of those value in a string:
<some_process_page.asp?MenteeNumber=...>

They are links, but hw can I get each of those to send their own value?


Thanks SO much,
Shane
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lshane

ASKER

Thank you both for your input.  I awarded kevp75 more points for the solution.

Thank you, basicinstinct, for jumping in and catching the details.

Thanks so much,
Shane

P.S. I may be back with another question related to this, as I would really like to show the Employee names that match these values, but I will see if I can get it to work over here.
thanks for the grade :)