Forums
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><%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/myconn.asp" -->
<%
Dim rsArticle__MMColParam
rsArticle__MMColParam = "1"
if (Request.QueryString("ID" <> "" then rsArticle__MMColParam = Request.QueryString("ID"
%>
<%
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
%>
<%
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
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
rsPeople_numRows = rsPeople_numRows + Repeat1__numRows
%>
<%
'pop the article text in a variable
varArticleText = rsArticle.Fields.Item("ArticleText".Value
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsPeople.EOF))
%>
<%
varString = "<a href=biography.asp?PersonName=" & rsPeople.Fields.Item("PersonName".Value & ">" & rsPeople.Fields.Item("PersonName".Value & "</a>"
varArticleText = Replace(varArticleText, rsPeople.Fields.Item("PersonName".Value, varString)
%>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsPeople.MoveNext()
Wend
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
<%= varArticleText %>
</body>
</html>
<%
rsArticle.Close()
%>
<%
rsPeople.Close()
%>
</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.... ::
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><%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/myconn.asp" -->
<%
Dim rsArticle__MMColParam
rsArticle__MMColParam = "1"
if (Request.QueryString("ID" <> "" then rsArticle__MMColParam = Request.QueryString("ID"
%>
<%
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
%>
<%
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
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
rsPeople_numRows = rsPeople_numRows + Repeat1__numRows
%>
<%
'pop the article text in a variable
varArticleText = rsArticle.Fields.Item("ArticleText".Value
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsPeople.EOF))
%>
<%
varString = "<a href=biography.asp?PersonName=" & rsPeople.Fields.Item("PersonName".Value & ">" & rsPeople.Fields.Item("PersonName".Value & "</a>"
varArticleText = Replace(varArticleText, rsPeople.Fields.Item("PersonName".Value, varString)
%>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsPeople.MoveNext()
Wend
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
<%= varArticleText %>
</body>
</html>
<%
rsArticle.Close()
%>
<%
rsPeople.Close()
%>
</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
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!!!!!
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.... ::
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.... ::