当前位置: 移动技术网 > IT编程>开发语言>Asp > 给万博系统的新闻系统增加分页功能[配有详细说明]

给万博系统的新闻系统增加分页功能[配有详细说明]

2017年12月12日  | 移动技术网IT编程  | 我要评论
给万博系统的新闻系统增加分页功能,无需修改数据库,只需改变一个文件,就可以了.
如果将后台的webediter增加一个插入分页符,那就更完美了.我还没加这个.

本例是在后台录入新闻时,在需要分页的位置插入分页符: {$html_page$} 就可以了.

代码如下,有详细说明
newsshow.asp

<!--#include file="siteinfo.asp"-->
<html>
<head>
<title><%=sitename%></title>
<meta http-equiv="content-type" c>
<link href="images/css.css" type=text/css rel=stylesheet>
</head>
<body  topmargin="0">
<table width="780" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3"><!--#include file="top.asp"--></td>
  </tr>
  <tr>
    <td width="145" align="left" valign="top"><!--#include file="left.asp" --></td>
    <td align="left" valign="top" ><table width="625"  border="0" cellspacing="0" cellpadding="0">

        <tr>
          <td width="17" height="20"> </td>
          <td width="598"> </td>
          <td width="10"> </td>
        </tr>
        <tr >
          <td width="17"><% idd=trim(request.querystring("id"))
             set rsr=server.createobject("adodb.recordset")
             sql="select * from news where  putout=true and id="&idd
             rsr.open sql,conn,1,3
    if not rsr.eof then

    newcontent=rsr("newcontent")
    newtitle=rsr("newtitle")
                putman=rsr("putman")
    kig=rsr("kig")
    kig=kig+1
    addtime=rsr("addtime")  
    rsr("kig")=kig
    rsr.update
    else
    response.write"找不到记录,发生导常错误,请联系管理员!"
    end if  
'这里要处理接收到的分页参数,以此来进行显示第几页的内容
'下面这两句就是如果没有page这个参数传来就让变量pagenum取显示第一页的值:0
if request("page")="" then
pagenum=0
'否则就给变量赋值为传递来的page里的参数,来显示其他页
else
pagenum=request("page")
end if
%>
<%
'如果加了可选执行ubb代码,可以加上下面的代码
'rs("noubb")是数据库里关于禁用ubb的字段,0为禁用,1为执行
'if rsr("noubb")=0 then
'为避免和文章内容相连出现错误,用replace函数把分页代码“{$html_page$}”的前后各加一个全角的
'rs("content")是数据库里正文的字段,在这里加上ubb或者禁用ubb
content=replace(newcontent,"{$html_page$}"," {$html_page$} ")
'elseif rsr("noubb")=1 then
'content=replace((ubb(newcontent)),"{$html_page$}"," {$html_page$} ")
'end if
%></td>
          <td height="22" align="center" class="news_title"><%=newtitle%><br>
<hr size="1" noshade  color="#666666"></td>
          <td width="10"> </td>
        </tr>
        <tr>
          <td rowspan="3"> </td>
          <td height="303" valign="top" ><%
'这里就是关键了
'我们用split函数将文章分段取出存入变量content
contentstr=split(content,"{$html_page$}")
'按照刚才从url参数中取得的要显示那面的那个变量,就循环显示一页
for i=pagenum to pagenum
%>
<!--这里将是文章正文内容-->
<%=contentstr(i) %>
<% next %></td>
          <td rowspan="3"> </td>
        </tr>
        <tr>
          <td height="8" valign="top">  </td>
        </tr>
        <tr>
          <td height="8" align="center" valign="top">本文共分
<%
'分页的地方,用ubound(contentstr)取得文章一共分为几页,注意这里是从0开始,所以总页数需要加1
for p = 0 to ubound(contentstr)
'链接还是本页面,只不过文章id参数后面还要加上一个分页的参数:page
%> 
<a href="newsshow.asp?id=<%=request("id")%>&page=<%=p%>" class=""><%=p+1%></a>
<% next %>页</td>
        </tr>
        <tr>
          <td height="40"> </td>
          <td height="60" valign="bottom"><table width="100%"  border="0" cellpadding="5" cellspacing="1" bgcolor="#cecece">
            <tr bgcolor="#ffffff" >
              <td width="16%" align="right" bgcolor="#cecece" >发 布  者:</td>
              <td width="20%" bgcolor="#ffffff"> <%=putman%></td>
              <td width="15%" align="right" bgcolor="#cecece">添加时间:</td>
              <td width="20%" bgcolor="#ffffff"> <%=addtime%></td>
              <td width="15%" align="right" bgcolor="#cecece">点  击  数:</td>
              <td width="15%"><%=kig%></td>
            </tr>
          </table></td>
          <td> </td>
        </tr>
    </table></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="3"><!--#include file="bot.asp"--></td>
  </tr>
</table>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网