Forums

ASP

This topic is locked

Dynamic Regular Expresions

Posted 24 Apr 2002 15:03:17
1
has voted
24 Apr 2002 15:03:17 Rian Carstens posted:
What I am trying to do is to create a dynamic regular expresion. Basically I am have a table that holds names of people. I want to create a dynamic search for all these people's names in an article page and link the names back to the persons detail page.

Here is an example for "Fidel":

"This is the body of the text where Fidel will be mentioned and wherever Fidel is mentioned it should be linked back to Fidel's biography page."

I do not want to have to hard code "fidel" in the script, since there is a huge list of changing names.

How can I specify that I need to search all the names in the table automaticaly?

Thank you in advance.

Rian

Replies

Replied 25 Apr 2002 03:29:53
25 Apr 2002 03:29:53 Andrew Watson replied:
Hello, Rian,

Im presuming that the article text comes from a database,

(If it doesn't just set the variable varArticleText to the text content of the article)
then, this will work...


<pre id=code><font face=courier size=2 id=code>&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="Connections/myconn.asp" --&gt;
&lt;%
Dim rsArticle__MMColParam
rsArticle__MMColParam = "1"
if (Request.QueryString("ID" &lt;&gt; "" then rsArticle__MMColParam = Request.QueryString("ID"
%&gt;
&lt;%
set rsArticle = Server.CreateObject("ADODB.Recordset"
rsArticle.ActiveConnection = MM_myconn_STRING
rsArticle.Source = "SELECT * FROM tblArticles WHERE ID = " + Replace(rsArticle__MMColParam, "'", "''" + ""
rsArticle.CursorType = 0
rsArticle.CursorLocation = 2
rsArticle.LockType = 3
rsArticle.Open()
rsArticle_numRows = 0
%&gt;
&lt;%
set rsPeople = Server.CreateObject("ADODB.Recordset"
rsPeople.ActiveConnection = MM_leed_STRING
rsPeople.Source = "SELECT * FROM tblPeople"
rsPeople.CursorType = 0
rsPeople.CursorLocation = 2
rsPeople.LockType = 3
rsPeople.Open()
rsPeople_numRows = 0
%&gt;
&lt;%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
rsPeople_numRows = rsPeople_numRows + Repeat1__numRows
%&gt;


&lt;%
'pop the article text in a variable
varArticleText = rsArticle.Fields.Item("ArticleText".Value
%&gt;

&lt;%
While ((Repeat1__numRows &lt;&gt; 0) AND (NOT rsPeople.EOF))
%&gt;
&lt;%
varString = "&lt;a href=biography.asp?PersonName=" & rsPeople.Fields.Item("PersonName".Value & "&gt;" & rsPeople.Fields.Item("PersonName".Value & "&lt;/a&gt;"
varArticleText = Replace(varArticleText, rsPeople.Fields.Item("PersonName".Value, varString)
%&gt;
&lt;%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsPeople.MoveNext()
Wend
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;br&gt;
&lt;br&gt;
&lt;%= varArticleText %&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;%
rsArticle.Close()
%&gt;
&lt;%
rsPeople.Close()
%&gt;
</font id=code></pre id=code>

Your biography page simply needs to have a recordset of pwople filtered on URL string PersonName.

Hope this is of some help.

Cheers, Leed.

:: Son, im Thirty.... ::
Replied 25 Apr 2002 12:29:17
25 Apr 2002 12:29:17 Hank Tan-Tenn replied:
The following search example uses RE to highlight keywords. While that is not what you need exactly, I believe the approach is similar:

udzone.com/showDetail.asp?TypeId=2&NewsId=1604

[edit]Never mind: I notice you've posed the same question under that tutorial as well. You ask, "How can I specify that I need to search all the names in the table automaticaly?" But it's not clear where your source of keywords (names in your case) comes from: <img src=../images/dmxzone/forum/icon_smile_question.gif border=0 align=middle>is it a database? A search form? A text file? A querystring? Or...?

Edited by - akc on 25 Apr 2002 13:03:37
Replied 25 Apr 2002 14:12:06
25 Apr 2002 14:12:06 Rian Carstens replied:
Absolutely Brilliant Leed, <img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>. No one has been able to help me with this for a long long long time.

You are a master!!!

Here is the page that it is being used on now, thanks to you this project will now be a success.

www.cubaheritage.com/articles.asp?artID=41

Thank you!!!!!
Replied 25 Apr 2002 14:39:05
25 Apr 2002 14:39:05 Andrew Watson replied:
Nae bother Rian,

hope your site IS a success, (it looks interesting by the way!)

Cheers, Leed

<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

:: Son, im Thirty.... ::

Reply to this topic