标题:分页出了问题,不知道怎么回事?
只看楼主
fengmnll
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-11-6
结帖率:85.71%
已结贴  问题点数:15 回复次数:7 
分页出了问题,不知道怎么回事?
<!--#include file="conn.asp"-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK
href="images/css.css" type=text/css rel=stylesheet>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>编辑课程信息</title>
</head>

<body  vLink=#000000 bgColor=#cad7f7>
<table width="655" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
  <tr>
    <td width="655" height="30">
            <table width="654" border="0" cellspacing="0" cellpadding="0">
                       <tr>
                  <td height="17" colspan="2">&nbsp;</td>
                       </tr>
         
                       <tr>
                         <td width="82" height="30">&nbsp;                         </td>
                         <td width="572">&nbsp;</td>
                       </tr>
    </table></td>
  </tr>
  <tr>
    <td height="30"><table width="653" border="0" cellpadding="0" cellspacing="0">
      
      <tr>
        <td width="60" height="32">
          <div align="center">学号 </div>
          </td>
        <td width="65" height="32"><div align="center">姓名</div></td>
        <td width="46" height="32"><div align="center">年龄</div></td>
        <td width="41" height="32"><div align="center">性别</div></td>
        <td width="80" height="32"><div align="center">进校时间</div></td>
        <td width="94" height="32"><div align="center">籍贯</div></td>
        <td width="159"><div align="center">专业</div></td>
      </tr>
      <%         
                  set rs=server.CreateObject("ADODB.Recordset")
                  rs.open "select  student_number,student_name,age,sex,in_time,homeplace,major from Student",conn ,1,3
               
                  if rs.eof and  rs.bof  then
                        response.Write"目前没有学生信息"
                  else              
                  counts=10
                  rs.pagesize=counts
                  allpages=rs.pageCount
                  page=request("page")
                  if not isNumeric(page)  then  page=1
                  if  isEmpty(page)  or   Cint(page)<1  then
                            page=1
                  else if  Cint(page)>=allPages  then
                            page=allPages
                  end  if
                  rs.AbsolutePage=page
                  Do  while(Not rs.eof)  and  counts>0
         %>                    
              
      
      <tr>
        <td height="25"><%=rs("student_number")%></td>
        <td width="65" height="25"><%=rs("student_name")%></td>
        <td><%=rs("age")%></td>
        <td><%=rs("sex")%></td>
        <td><%=rs("in_time")%></td>
        <td><%=rs("homeplace")%></td>
        <td><%=rs("major")%></td>
        </tr>
      <%
            counts=counts-1
            rs.movenext
             if  rs.eof  then exit  do
               loop
               end if
             %>
    </table></td>
  </tr>
</table>
  <table width="653" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
  <tr>
    <td height="30" align="center">      
    <%
         response.Write"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前共有"&rs.recordcount&"条用户记录"
      if  page=1 then  
         response.Write"<font color=darkgray>&nbsp;&nbsp;首页  前页</font>"
      else
         response.Write"<a href=pagesview.asp?page=1>首页</a>  <a href=pagesview.asp?page="&page-1&">&nbsp;&nbsp;前页</a>"
     end  if
     if page=allPages  then
          response.Write"<font color=darkgray>下页&nbsp;&nbsp; 末页</font>"            
     else        
          response.Write"<a href=pagesview.asp?page="&page+1&">下页</a> <a href=pagesview.asp?page="&allPages&">末页</a>"
     end if
          response.Write" 第"&page&"页 共"&allPages&"页 "        
          end if
    %>
   
    </td>
  </tr>
</table>

</body>
</html>
页面不显示学生信息,只显示工业多少条信息,不知道是什么地方出错了,就是个分页结构.谢谢
搜索更多相关主题的帖子: html head content include PUBLIC 
2010-05-17 16:19
fengmnll
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-11-6
得分:0 

显示就是这样子的
2010-05-17 16:21
魏兴耀
Rank: 8Rank: 8
来 自:江西
等 级:蝙蝠侠
威 望:3
帖 子:246
专家分:840
注 册:2009-11-9
得分:10 
关于分页的做法我之前也苦恼了很久,但反复理解以后就好了,我就先说一下较容易出错的地方:
1:把rs.AbsolutePage漏了
2:传值时把变量写错了
我给你一个我自己写的代码,都有注释,这个事例很简单易懂,会对你有帮助的
<% Option Explicit %>
<!--#Include file="odbc_connection.asp"-->
<!--#Include file="config.asp"-->
<html>
<head>
    <title>我的通讯录</title>
</head>
<body>
    <h1 align="center">通讯录</h1>

    <!--下面首先给添加记录和查找记录的超链接 -->
    <a href="insert.asp">添加记录</a>&nbsp;&nbsp;<a href="search.asp">查找记录</a><p>

    <%
    '下面首先获取传递过来的排序字段名称-------------------------------------------------------------
    Dim strField
    If Request.QueryString("varField")="" Then
        strField="ID"                                        '如果为空,就默认按编号字段排序
    Else
        strField=Request.QueryString("varField")            '如果不为空,就按相应字段排序
    End If
    '下面一段判断当前显示第几页,如是第一次打开,为1,否则由传回参数决定
    Dim intPage                           
    If Request.QueryString("varPage")="" Then   
        intPage=1
    Else
        intPage=CInt(Request.QueryString("varPage"))        '用CInt转换为整数
    End If
   
    '以下建立Recordset对象实例rs,注意SQL语句中要用到上面获取的排序字段-----------------------------
    Dim rs,strSql
    Set rs=Server.CreateObject("ADODB.Recordset")
    strSql ="Select ID,strName,strTel,strEmail,dtmSubmit From tbAddress Order By " & strField & " DESC"
    rs.Open strSql,conn,1                                    '注意参数设置为键盘指针

    '如果记录集不是空的,就执行分页显示
    If Not rs.Bof And Not rs.Eof Then
        '-------------------------------------------------------------------------------------------
        '下面一段开始分页显示,指向要显示的页,然后逐条显示当前页的所有记录
        rs.PageSize=conPageSize                                '这里调用config.asp中的常数设置每页显示多少条记录
        rs.AbsolutePage=intPage                                '设置当前显示第几页

        '下面首先输出表格的标题栏
        Response.Write "<table width='100%' border='1' bordercolorlight='#B0B0B0' bordercolordark='#FFFFFF' cellspacing='0' cellpadding='0' align='center'>"
        Response.Write "<tr bgcolor='#E0E0E0' height='25'>"
        Response.Write "<th width='10%'><a href='index.asp?varField=ID'>编号</a></th>"
        Response.Write "<th width='10%'><a href='index.asp?varField=strName'>姓名</a></th>"
        Response.Write "<th width='20%'><a href='index.asp?varField=strTel'>电话</a></th>"
        Response.Write "<th width='20%'><a href='index.asp?varField=strEmail'>E-mail</a></th>"
        Response.Write "<th width='20%'><a href='index.asp?varField=dtmSubmit'>添加日期</a></th>"
        Response.Write "<th width='10%'>更新</th>"
        Response.Write "<th width='10%'>删除</th>"
        Response.Write "</tr>"

        '下面利用循环显示当前页的所有记录
        Dim I
        For I=1 To rs.PageSize
            If rs.Eof Then Exit For                            '如果到了记录集结尾,就跳出循环
            Response.Write "<tr align='center' height='25'>"                                
            Response.Write "<td>" & rs("ID") & "</td>"
            Response.Write "<td><a href='particular.asp?ID=" & rs("ID") & "' target='_blank'>" & rs("strName") & "</td>"
            Response.Write "<td>" & rs("strTel") & "</td>"
            Response.Write "<td><a href='mailto:" & rs("strEmail") & "'>" & rs("strEmail") & "</td>"
            Response.Write "<td>" & rs("dtmSubmit") & "</td>"
            Response.Write "<td><a href='update.asp?ID=" & rs("ID") & "'>更新</td>"
            Response.Write "<td><a href='delete.asp?ID=" & rs("ID") & "'>删除</td>"
            Response.Write "</tr>"
            rs.MoveNext
        Next
        '下面输出表格的结束标记,表格到此结束
        Response.Write "</table>"

        '-------------------------------------------------------------------------------
        '下面首先输出当前页和总页数
        Response.Write "<p align='right'>当前显示第" & intPage & "页/共" & rs.PageCount & "页"

        '下面一段依次输出第1页、上一页、下一页和最后页的超链接
        Response.Write "&nbsp;&nbsp;<a href='index.asp?varPage=1&varField=" & strField & "'>第1页</a>&nbsp;"
        If intPage>1 Then
            Response.Write "<a href='index.asp?varPage=" & (intPage-1) & "&varField=" & strField & "'>上一页</a>&nbsp;"
        Else
            Response.Write "上一页&nbsp;"
        End If
        If intPage<rs.PageCount Then
            Response.Write "<a href='index.asp?varPage=" & (intPage+1) & "&varField=" & strField & "'>下一页</a>&nbsp;"
        Else
            Response.Write "下一页&nbsp;"
        End If
        Response.Write "<a href='index.asp?varPage=" & rs.PageCount  & "&varField=" & strField & "'>最后页</a>&nbsp;"
        '-------------------------------------------------------------------------------
    End If
    '现在关闭有关对象
    rs.Close
    Set rs=Nothing
    conn.Close
    Set conn=Nothing
    %>
</body>
</html>

只有大胆尝试,才有机会得到想要的成功
2010-05-17 16:29
fengmnll
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-11-6
得分:0 
回复 3楼 魏兴耀
看起来还是有点晕
2010-05-17 16:55
fengmnll
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-11-6
得分:0 
有没有人在帮忙看看,谢谢了
2010-05-17 17:45
fengmnll
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-11-6
得分:0 
回复 3楼 魏兴耀
不过还是很感谢你,谢谢
2010-05-17 17:58
魏兴耀
Rank: 8Rank: 8
来 自:江西
等 级:蝙蝠侠
威 望:3
帖 子:246
专家分:840
注 册:2009-11-9
得分:0 
回复 6楼 fengmnll
前两天断网了,你可以加我QQ,我们可以一起学习,276639687。名字就是我在论坛里的名字

只有大胆尝试,才有机会得到想要的成功
2010-05-20 10:25
fengmnll
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-11-6
得分:0 
回复 6楼 fengmnll
好的,谢谢
2010-05-20 10:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-307031-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.453904 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved