Firstly, please forgive me if the way I ask this question doesn't make sense as I'm not sure how to put it, but here goes.

I have a list of items in a menu which link to a records in a database. The user can click on a link which opens a form to allow alterations to the record, however, if the field starts with a link (<a href...), then it doesn't show up in the list.

The SQL code is:

SELECT ResourceID,  LEFT (ResourceContent, 40) AS ResourceContent
FROM tblResources
WHERE YouTubeLink IS NULL AND DisplayRecord = 1
ORDER BY PositionNumber ASC

The output for the SQL code is:

Record  ResourceID  ResourceContent
1       1           <p><a href="../../other-files/Annual-Rep
2       2           <p>Click here to see the most recent MfM
3       3           <p>Click here to read the latest newslet
4       7           <p>Here is a load of text that will be u

The menu code is:

<h3><%=(rsContent.Fields.Item("MainMenuName").Value)%></h3>

<ul>

<li class="menuHeading"><%=(rsContent.Fields.Item("SubMenuName").Value)%></li>
<li class="menuList brown" style="margin-left:-15px">Documents</li>
<% 
While ((RepeatNonMedia__numRows <> 0) AND (NOT rsNonMedia.EOF)) 
%>
  <li id="resourceMenuList"><a href="resources-modify-document-record.asp?idVal=<%=(rsNonMedia.Fields.Item("ResourceID").Value)%>"><%=(rsNonMedia.Fields.Item("ResourceContent").Value)%>...</li>
  <% 
  RepeatNonMedia__index=RepeatNonMedia__index+1
  RepeatNonMedia__numRows=RepeatNonMedia__numRows-1
  rsNonMedia.MoveNext()
Wend
%>

<li class="menuList brown" style="margin-left:-15px">Videos</li>
<% 
While ((RepeatMedia__numRows <> 0) AND (NOT rsMedia.EOF)) 
%>
  <li id="resourceMenuList"><a href="resources-modify-video-record.asp?idVal=<%=(rsMedia.Fields.Item("ResourceID").Value)%>"><%=(rsMedia.Fields.Item("YouTubeCaption").Value)%>...</a></li>
  <% 
  RepeatMedia__index=RepeatMedia__index+1
  RepeatMedia__numRows=RepeatMedia__numRows-1
  rsMedia.MoveNext()
Wend
%>
<% 
While ((RepeatAddRecord__numRows <> 0) AND (NOT rsAddRecord.EOF)) 
%>
<%
    fName = Replace (rsAddRecord.Fields.Item("SubMenuName").Value," ","-")
    fName = Lcase(fName)
%>
  <li class="menuHeading"><a href="<% Response.Write(fName) %>-modify-record.asp"><%=(rsAddRecord.Fields.Item("SubMenuName").Value)%></a></li>
  <% 
  RepeatAddRecord__index=RepeatAddRecord__index+1
  RepeatAddRecord__numRows=RepeatAddRecord__numRows-1
  rsAddRecord.MoveNext()
Wend
%>

<li class="menuHeading"><a href="learn-more-modify-record.asp?mmID=<%=(rsAddRecordExtra.Fields.Item("MainMenuID").Value)%>&smID=<%=(rsAddRecordExtra.Fields.Item("SubMenuID").Value)%>"><%=(rsAddRecordExtra.Fields.Item("SubMenuName").Value)%></a></li>
</ul>

The output to the webpage is similar to:

Learn More

Resources
   Documents
      Click here to see the most recent MfM...
      Click here to read the latest newslet...
      Here is a load of text that will be u...
  Videos
      Money for Madagascar - Our Work in Pictu...
      Money for Madagascar - Our Work in Pictu...
      Bambi's mother comes back from the dead ...
Case Studies
Friends Of MfM
The Welsh Connection

As you can see, the SQL outputs the record but the code doesn't recognise it. If the link is outside the 40th character there is no problem, however, if the link is inside of the 40th character, the listing truncates to the <a href... tag.

I've tried using <% Response.Write() %> to surround the <li> tag info but no luck. If I remove all formatting, use just basic HTML code, still no luck.

I thought about using a regexp to remove the link code (including the end tag) but I don't no enough about regexp to write it.

Any hoo, can you help me resolve this problem?

Many thanks in advance.

有帮助吗?

解决方案 2

Here's what I did.

I removed the code limiting the characters from the SQL statement. I then replaced the <a\b[^>]*> in safetyOtter's code with <[^>]*>. This regex code removes all the html code in the field. I then added more code that then renamed the regex output. This I then used in the <a> tag to limit the number of characters displayed.

New SQL code

SELECT ResourceID, ResourceContent
FROM tblResources
WHERE YouTubeLink IS NULL AND DisplayRecord = 1
ORDER BY PositionNumber ASC

The regex code

<%
set regex = New RegExp
regex.Pattern = "<[^>]*>"
regex.Global = true
regex.IgnoreCase = true
%>

Code to rename the regex added after the <% While... %> statement

<%
ResourceContent = regex.Replace((rsNonMedia.Fields.Item("ResourceContent").Value),"")
%>

HTML code

<a href="resources-modify-document-record.asp?idVal=<%=(rsNonMedia.Fields.Item("ResourceID").Value)%>"><%=LEFT(ResourceContent,40)%>...</a>

其他提示

Just out of curiosity, try replacing

<%=(rsNonMedia.Fields.Item("ResourceContent").Value)%>

with

<%=Replace((rsNonMedia.Fields.Item("ResourceContent").Value),"<a ","<gibberish")%>

Edit:

just above your replace someplace safe, prolly just over the start of the while:

set regex = New RegExp
regex.Pattern = "<a\b[^>]+>"
regex.Global = true
regex.IgnoreCase = true

then replace

<%=(rsNonMedia.Fields.Item("ResourceContent").Value)%>

with

<%=regex.Replace((rsNonMedia.Fields.Item("ResourceContent").Value),"")%>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top