消失的菜单项

时间:2014-03-01 15:34:20

标签: sql asp-classic dreamweaver

首先,请原谅我,如果我问这个问题的方式没有意义,因为我不知道怎么说,但是这里有。

我在菜单中有一个项目列表,链接到数据库中的记录。用户可以单击打开表单的链接以允许更改记录,但是,如果字段以链接(<a href...)开头,则它不会显示在列表中。

SQL代码是:

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

SQL代码的输出是:

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

菜单代码为:

<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>

网页的输出类似于:

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

如您所见,SQL输出记录但代码无法识别它。如果链接在第40个字符之外没有问题,但是,如果链接在第40个字符内,则列表会截断为<a href...标记。

我尝试使用<% Response.Write() %>包围<li>代码信息,但没有运气。如果我删除所有格式,只使用基本的HTML代码,仍然没有运气。

我考虑过使用正则表达式来删除链接代码(包括结束标记),但我对regexp的写法不够。

任何hoo,你能帮我解决这个问题吗?

非常感谢提前。

2 个答案:

答案 0 :(得分:0)

出于好奇,请尝试替换

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

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

编辑:

就在你的替换安全的地方上方,在刚开始的时候多了:

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

然后替换

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

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

答案 1 :(得分:0)

这就是我的所作所为。

我删除了限制SQL语句中字符的代码。然后我用<a\b[^>]*>替换了safeOtter代码中的<[^>]*>。此正则表达式代码删除该字段中的所有html代码。然后我添加了更多代码,然后重命名了正则表达式输出。然后我在<a>标签中使用它来限制显示的字符数。

新SQL代码

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

正则表达式代码

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

重命名<% While... %>语句后添加的正则表达式的代码

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

HTML代码

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