本人又在上面基础上加了单字段显示,按指定字段排序,链连指定字段的功能,
修改后的函数如下:
<%
'通用记录显示函数
'作者 无根泉
'最后更新2005-6-7
'功能:支持access,ms sql server,数据库,
'自定义显示数据表的记录,自定义链接字段、格式,分页显示记录,管理权限识别,
'自定义文字说明,字段显示......
sub showrd(tname,ttype,table,url,action,width,height,sessionname,sessionqx,id)
if width="" then width="400"
if height="" then height="300"
set rs=server.CreateObject("adodb.recordset")
sql="select * from "&table&" order by "&id&" desc"
rs.pagesize=20
rs.open sql,conn,3,2
if rs.eof then
%>
<table width="740" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="30"><center>
当前没有数据![<a href="#" onClick="open('<%= action %>?action=add','','width=<%=width %>,height=<%= height %>')">添加版块</a>]
</center></td>
</tr>
</table>
<% else
ipage=0
if rs.pagecount<page then page=rs.pagecount
rs.absolutepage=page
%>
<table width="740" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#555555" style="border-left:0px; ">
<tr bgcolor="#BDCBDE">
<td width="5%" height="30"><center>
<strong>编号</strong>
</center></td>
<%
if instr(tname,"|")=0 then
%><td width="477"><center>
<strong><%= tname %></strong>
</center></td>
<%
else
tn=split(tname,"|")
for tn1=0 to ubound(tn) %>
<td width="477"><center>
<strong><%= tn(tn1) %></strong>
</center></td>
<% next
end if%>
<% If sessionname<>"" or isempty(sessionname)=false Then
if sessionname>sessionqx then%>
<td width="15%"><center>
<strong>操作</strong>
</center></td>
<% end if
end if %>
</tr>
<% do while not rs.eof and ipage<rs.pagesize
if page=1 then
bh=(ipage+1)
else
bh=(page-1)*rs.pagesize+(ipage+1)
end if
if bh mod 2=0 then
color="#DEE3ED"
else
color="#eeeeee"
end if
%>
<tr bgcolor="<%=color%>">
<td height="26">&nbsp;&nbsp;<%=bh %></td>
<%
if instr(ttype,"|")<>0 then
tty=split(ttype,"|")
for tt1=0 to ubound(tty)
tnm=tty(tt1)%>
<td><%
if instr(tnm,"$")=0 then
response.Write rs(tnm)
else
u1=split(tnm,"$")
'if instr(u1(1),"id")<>0 then
response.Write "<a href="&u1(1)&rs(id)&" target='_blank'>"&rs(u1(0))&"</a>"
'else
'response.Write "<a href="&u1(1)&rs(u1(0))&" target='_blank'>"&rs(u1(0))&"</a>"
'end if
end if%>&nbsp;&nbsp;</td>
<% next
else
response.Write"<td>"
if instr(ttype,"$")=0 then
response.Write rs(ttype)
else
u1=split(ttype,"$")
'if instr(u1(1),"id")<>0 then
response.Write "<a href="&u1(1)&rs(id)&" target='_blank'>"&rs(u1(0))&"</a>"
'else
'response.Write "<a href="&u1(1)&rs(u1(0))&" target='_blank'>"&rs(u1(0))&"</a>"
'end if
end if
response.Write"</td>"
end if%>
<% If sessionname<>"" or isempty(sessionname)=false Then
if sessionname>sessionqx then%>
<td><center>
[<a href="#" onClick="open('<%= action %>?action=add','','width=<%=width %>,height=<%=height %>')">添加</a>][<a href="#" onClick="open('<%= action %>?action=edit&id=<%= rs(0) %>','','width=<%=width %>,height=<%=height %>')">修改</a>][<a href="#" onClick="open('<%= action %>?action=del&id=<%= rs(0) %>','','width=200,height=10')">删除</a>]
</center></td>
<% end if
end if %>
</tr>
<% ipage=ipage+1
rs.movenext
loop %>
<tr bgcolor="#BDCBDE">
<td height="24" colspan="<%=tt1+3 %>">&nbsp;<% call showpage(rs.recordcount,rs.pagesize,page,url)%></td>
</tr>
<% end if
rs.close
set rs=nothing%>
</table>
<% end sub %>
此函数同上次发的那个分页函数一起用,
分页函数如下:
<%
function showpage(cnt,size,page,url)
cot=int(cnt/size)
ca=cnt mod size
if ca<>0 then
cot=cot+1
else
cot=cot
end if
if page>cot then page=cot
response.Write"共"&cnt&"条&nbsp;每页"&size&"条&nbsp;页次:"&page&"/"&cot&"&nbsp;"
if page=1 then
response.Write "[首页]&nbsp;[上页]&nbsp;"
else
response.Write"[<a href="&url&"page=1>首页</a>]&nbsp;[<a href="&url&"page="&page-1&">上页</a>]&nbsp;"
end if
if page=cot then
response.Write "[下页]&nbsp;[尾页]&nbsp;"
else
response.Write"[<a href="&url&"page="&page+1&">下页</a>]&nbsp;[<a href="&url&"page="&cot&">尾页</a>]&nbsp;"
end if
response.Write"<select name='page' onchange='sed(this.value)'>"
for i=1 to cot
response.Write"<option value='"&i&"'"
if i=page then response.Write "selected"
response.Write">"&i&"</option>"
next
response.Write"</select>"
response.Write"<script>"
response.Write"function sed(x){"
response.Write"window.location='"&url&"page='+x;"
response.Write"}</script>"
end function%>
你所要做的就是把这二个函数拷下来,
修改一下要显示的文字,和要检索的字段!
修改后的函数如下:
<%
'通用记录显示函数
'作者 无根泉
'最后更新2005-6-7
'功能:支持access,ms sql server,数据库,
'自定义显示数据表的记录,自定义链接字段、格式,分页显示记录,管理权限识别,
'自定义文字说明,字段显示......
sub showrd(tname,ttype,table,url,action,width,height,sessionname,sessionqx,id)
if width="" then width="400"
if height="" then height="300"
set rs=server.CreateObject("adodb.recordset")
sql="select * from "&table&" order by "&id&" desc"
rs.pagesize=20
rs.open sql,conn,3,2
if rs.eof then
%>
<table width="740" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="30"><center>
当前没有数据![<a href="#" onClick="open('<%= action %>?action=add','','width=<%=width %>,height=<%= height %>')">添加版块</a>]
</center></td>
</tr>
</table>
<% else
ipage=0
if rs.pagecount<page then page=rs.pagecount
rs.absolutepage=page
%>
<table width="740" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#555555" style="border-left:0px; ">
<tr bgcolor="#BDCBDE">
<td width="5%" height="30"><center>
<strong>编号</strong>
</center></td>
<%
if instr(tname,"|")=0 then
%><td width="477"><center>
<strong><%= tname %></strong>
</center></td>
<%
else
tn=split(tname,"|")
for tn1=0 to ubound(tn) %>
<td width="477"><center>
<strong><%= tn(tn1) %></strong>
</center></td>
<% next
end if%>
<% If sessionname<>"" or isempty(sessionname)=false Then
if sessionname>sessionqx then%>
<td width="15%"><center>
<strong>操作</strong>
</center></td>
<% end if
end if %>
</tr>
<% do while not rs.eof and ipage<rs.pagesize
if page=1 then
bh=(ipage+1)
else
bh=(page-1)*rs.pagesize+(ipage+1)
end if
if bh mod 2=0 then
color="#DEE3ED"
else
color="#eeeeee"
end if
%>
<tr bgcolor="<%=color%>">
<td height="26">&nbsp;&nbsp;<%=bh %></td>
<%
if instr(ttype,"|")<>0 then
tty=split(ttype,"|")
for tt1=0 to ubound(tty)
tnm=tty(tt1)%>
<td><%
if instr(tnm,"$")=0 then
response.Write rs(tnm)
else
u1=split(tnm,"$")
'if instr(u1(1),"id")<>0 then
response.Write "<a href="&u1(1)&rs(id)&" target='_blank'>"&rs(u1(0))&"</a>"
'else
'response.Write "<a href="&u1(1)&rs(u1(0))&" target='_blank'>"&rs(u1(0))&"</a>"
'end if
end if%>&nbsp;&nbsp;</td>
<% next
else
response.Write"<td>"
if instr(ttype,"$")=0 then
response.Write rs(ttype)
else
u1=split(ttype,"$")
'if instr(u1(1),"id")<>0 then
response.Write "<a href="&u1(1)&rs(id)&" target='_blank'>"&rs(u1(0))&"</a>"
'else
'response.Write "<a href="&u1(1)&rs(u1(0))&" target='_blank'>"&rs(u1(0))&"</a>"
'end if
end if
response.Write"</td>"
end if%>
<% If sessionname<>"" or isempty(sessionname)=false Then
if sessionname>sessionqx then%>
<td><center>
[<a href="#" onClick="open('<%= action %>?action=add','','width=<%=width %>,height=<%=height %>')">添加</a>][<a href="#" onClick="open('<%= action %>?action=edit&id=<%= rs(0) %>','','width=<%=width %>,height=<%=height %>')">修改</a>][<a href="#" onClick="open('<%= action %>?action=del&id=<%= rs(0) %>','','width=200,height=10')">删除</a>]
</center></td>
<% end if
end if %>
</tr>
<% ipage=ipage+1
rs.movenext
loop %>
<tr bgcolor="#BDCBDE">
<td height="24" colspan="<%=tt1+3 %>">&nbsp;<% call showpage(rs.recordcount,rs.pagesize,page,url)%></td>
</tr>
<% end if
rs.close
set rs=nothing%>
</table>
<% end sub %>
此函数同上次发的那个分页函数一起用,
分页函数如下:
<%
function showpage(cnt,size,page,url)
cot=int(cnt/size)
ca=cnt mod size
if ca<>0 then
cot=cot+1
else
cot=cot
end if
if page>cot then page=cot
response.Write"共"&cnt&"条&nbsp;每页"&size&"条&nbsp;页次:"&page&"/"&cot&"&nbsp;"
if page=1 then
response.Write "[首页]&nbsp;[上页]&nbsp;"
else
response.Write"[<a href="&url&"page=1>首页</a>]&nbsp;[<a href="&url&"page="&page-1&">上页</a>]&nbsp;"
end if
if page=cot then
response.Write "[下页]&nbsp;[尾页]&nbsp;"
else
response.Write"[<a href="&url&"page="&page+1&">下页</a>]&nbsp;[<a href="&url&"page="&cot&">尾页</a>]&nbsp;"
end if
response.Write"<select name='page' onchange='sed(this.value)'>"
for i=1 to cot
response.Write"<option value='"&i&"'"
if i=page then response.Write "selected"
response.Write">"&i&"</option>"
next
response.Write"</select>"
response.Write"<script>"
response.Write"function sed(x){"
response.Write"window.location='"&url&"page='+x;"
response.Write"}</script>"
end function%>
你所要做的就是把这二个函数拷下来,
修改一下要显示的文字,和要检索的字段!
[此贴子已经被作者于2005-6-8 13:25:17编辑过]
我很菜,但我很努力!