ASP中如何控制从content字段取出的字符串
<!--#includefile="conn.asp"--><%Setrs=Server.CreateObject("ADODB.Recordset")sql="sele...
<!--#include file="conn.asp"-->
<%
Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from comment where id<>'' order by id desc"
rs.open sql,conn,1,1
if rs.bof then
Response.Write("现在没有评论。")
Response.end
end if
%>
<script>
function test()
{
if(!confirm('确认删除吗?')) return false;
}
</script>
<table width="790" height="31" border="0" cellpadding="0" cellspacing="1">
<tr>
<td width="111" bgcolor="#dddddd"><div align="center">大名</div></td>
<td width="269" bgcolor="#dddddd"><div align="center">网址</div></td>
<td width="193" bgcolor="#dddddd"><div align="center">内容</div></td>
<td width="143" bgcolor="#dddddd"><div align="center">IP</div></td>
<td width="68" bgcolor="#dddddd"><div align="center">删除</div></td>
</tr>
<%
rs.pagesize=30
currentpage=Clng(request("page"))
if currentpage<1 then currentpage=1
if currentpage>rs.pagecount then currentpage=rs.pagecount
rs.absolutepage=currentpage
do while not rs.eof
%>
<tr>
<td><div align="center">【<%= rs("zz").value%>】</div></td>
<td><div align="center"><%= rs("www").value%></div></td>
<td><%= rs("content").value%>
</td>
<td><div align="center"><%= rs("ip").value%></div></td>
<td><div align="center">删除</div></td>
</tr>
<%
i=i+1
rs.MoveNext
If i>=rs.pagesize Then Exit Do
Loop
%>
</table>
<form id="form1" name="form1" method="post" width="790" action="">
<table width="790" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#dddddd"><div align="center">共有评论:<%=rs.recordcount%> (<%=rs.pagecount%>页)
<%if currentpage>1 then%>
<a href="pinglun.asp" class="black">首页</a> <a href="pinglun.asp?page=<%=currentpage-1%>" class="black"> 上一页</a>
<%end if%>
<%if currentpage<rs.pagecount then%>
<a href="pinglun.asp?page=<%=currentpage+1%>" class="black">下一页</a> <a href="pinglun.asp?page=<%=rs.pagecount%>" class="black">尾页</a>
<%end if%>
<input name="search" type="hidden" id="search" value="<%=search%>" />
<input name="key" type="hidden" id="key" value="<%=key%>" />
</div></td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
在这段代码中只能实现从数据库读取content字段里的所有内容 我只需要他显示80字节就可以了 展开
<%
Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from comment where id<>'' order by id desc"
rs.open sql,conn,1,1
if rs.bof then
Response.Write("现在没有评论。")
Response.end
end if
%>
<script>
function test()
{
if(!confirm('确认删除吗?')) return false;
}
</script>
<table width="790" height="31" border="0" cellpadding="0" cellspacing="1">
<tr>
<td width="111" bgcolor="#dddddd"><div align="center">大名</div></td>
<td width="269" bgcolor="#dddddd"><div align="center">网址</div></td>
<td width="193" bgcolor="#dddddd"><div align="center">内容</div></td>
<td width="143" bgcolor="#dddddd"><div align="center">IP</div></td>
<td width="68" bgcolor="#dddddd"><div align="center">删除</div></td>
</tr>
<%
rs.pagesize=30
currentpage=Clng(request("page"))
if currentpage<1 then currentpage=1
if currentpage>rs.pagecount then currentpage=rs.pagecount
rs.absolutepage=currentpage
do while not rs.eof
%>
<tr>
<td><div align="center">【<%= rs("zz").value%>】</div></td>
<td><div align="center"><%= rs("www").value%></div></td>
<td><%= rs("content").value%>
</td>
<td><div align="center"><%= rs("ip").value%></div></td>
<td><div align="center">删除</div></td>
</tr>
<%
i=i+1
rs.MoveNext
If i>=rs.pagesize Then Exit Do
Loop
%>
</table>
<form id="form1" name="form1" method="post" width="790" action="">
<table width="790" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#dddddd"><div align="center">共有评论:<%=rs.recordcount%> (<%=rs.pagecount%>页)
<%if currentpage>1 then%>
<a href="pinglun.asp" class="black">首页</a> <a href="pinglun.asp?page=<%=currentpage-1%>" class="black"> 上一页</a>
<%end if%>
<%if currentpage<rs.pagecount then%>
<a href="pinglun.asp?page=<%=currentpage+1%>" class="black">下一页</a> <a href="pinglun.asp?page=<%=rs.pagecount%>" class="black">尾页</a>
<%end if%>
<input name="search" type="hidden" id="search" value="<%=search%>" />
<input name="key" type="hidden" id="key" value="<%=key%>" />
</div></td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
在这段代码中只能实现从数据库读取content字段里的所有内容 我只需要他显示80字节就可以了 展开
2个回答
展开全部
定义部分:
Function leftString(str,length)
dim x,y,i,s
s=str
x = len(str)
y = 0
if x >= 1 then
for i = 1 to x
if asc(mid(str,i,1)) < 0 or asc(mid(str,i,1)) >255 then
y = y + 2
else
y = y + 1
end if
if y >= length then
s = left(str,i) '字符串字节数
exit for
end if
next
end if
leftString = s
End Function
取出部分:<%=leftString(rs("content"),80)%>
Function leftString(str,length)
dim x,y,i,s
s=str
x = len(str)
y = 0
if x >= 1 then
for i = 1 to x
if asc(mid(str,i,1)) < 0 or asc(mid(str,i,1)) >255 then
y = y + 2
else
y = y + 1
end if
if y >= length then
s = left(str,i) '字符串字节数
exit for
end if
next
end if
leftString = s
End Function
取出部分:<%=leftString(rs("content"),80)%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询