달력

52025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
반응형

출처:http://www.devpia.com/forum/BoardView.aspx?no=269&forumname=www_lec

<%
  set conn = Server.CreateObject("ADODB.Connection")
  conn.open "mydb","",""

  pagesize=15   ' 한화면에 보여질 레코드의 갯수입니다.
  page=cInt(request.QueryString("page"))
    ' page : 현재 보여질 페이지입니다.
  if page=0 then
    page=1
  end if

  sql="SELECT count(*) FROM tb_table"

' 전체 자료의 갯수를 알기 위해서 별도의 레코드셋을 만들어야죠
' 이렇게 안하려고 했지만, 어쩔 수 없이 이렇게 해야 할 것 같아서요.
' 혹시 다른 좋은 방법이 있으면, 조언 부탁드립니다.

  Set rs=conn.Execute(sql)
  tot_cnt=cInt(rs(0))   ' 전체 자료 갯수
  rs.close
  Set rs=nothing

  Set rs=Server.CreateObject("ADODB.Recordset")
  rs.CursorType=1  ' 이 속성은 엑세스에서는 안되는 것 같던데...

  sql="SELECT id_no,name,title FROM tb_table"

  if tot_cnt=0 then  ' 테이블에 레코드가 하나도 없으면,
                     ' all_value=rs.getrows(...) 이 부분에서 에러가 나요.
    response.write "<center><font size=5><b>검색 자료가 없습니다.</b></font>"
    response.write "<form><input type=button value='다시하기' onClick=history.back
()></form></center>"
    response.end
  else
    rs.open sql,Conn
    all_value=rs.getrows(pagesize*page)
' 여기서 all_value=rs.getrows 라고만 쓰면, 전체 레코드를 모두 가져오죠.
' 앞에서 소개한 테이블에서는 1762개를 몽땅 가져오는 거죠...
' 그렇게 해도 되긴한데, 그렇게 했을 때는 1페이지를 볼 때나
' 마지막 페이지를 볼 때나 동일하게 12초가 걸리더군요... 당연한가?
    rs.close
    set rs=nothing
  end if

  tot_page=tot_cnt\pagesize     ' 전체 페이지 수(\ 역슬래쉬입니다.)
                                ' 역슬래쉬는 몫을 구한거라는 거 다 아시죠?
  if tot_cnt mod pagesize <> 0 then  ' mod 는 나머지를 구하는 거죠.
    tot_page=tot_page+1
  end if
%>
 
<html>
<head>
<title>테스트 페이지입니다.</title>
<script LANGUAGE="JavaScript">
<!--
  function go_page(page) {
    url="display.asp?page=" & page;
    win1=window.open(url,"_self");
  }
-->
</script>
</head>

<body bgcolor="#FFFAF0">
<form>
<table border="0" width="85%">
  <tr>
    <td>총자료건수 : <%=tot_cnt%> </td>
    <td align="right">  <!-- 페이지 이동을 유연하게 할 수 있죠 -->
      <select name="selectpage" onChange="go_page(this.options
[this.selectedIndex].value,0)">
<%
  for i=1 to tot_page
    if i=page then
%>
        <option selected value="<%=i%>"><%=i%></option>
<%
    else
%>
        <option value="<%=i%>"><%=i%></option>
<%
    end if
  next
%>
      </select><font size="3"><b>/<%=tot_page%> page</b></font>
    </td>  <!-- 여기까지가 페이지 이동 선택 폼입니다. -->
  </tr>
</table>
<table width="85%" border="0" cellpadding="0" cellspacing="1"><tr><td
align="center" bgcolor="black">
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<!-- 이렇게 테이블을 두개를 사용하는 이유는 넷츠케이프와 익스플로러에서
      동일하게 보이도록 하려는 것입니다. 넷츠케이프에서도 얇은 선으로 표시되죠 -->
  <tr bgcolor="#bad4d3">
    <td width="10%" align="center">번  호</td>
    <td width="15%" align="center">작성자</td>
    <td width="75%" align="center">제  목</td>
  </tr>
<%
  s_cnt=(page-1)*pagesize
  e_cnt=s_cnt+pagesize-1
  if e_cnt>tot_cnt then
    e_cnt=tot_cnt-1
  end if
  for i=s_cnt to e_cnt  ' 이렇게 루프를 돌리면 되죠....
%>
  <tr bgcolor="#F5FFF5">
    <td align="center"><%=all_value(0,i)%></td>
    <td align="center"><%=all_value(1,i)%></td>
    <td><a href="view.asp?id_no=<%=all_value(0,i)%>&page=<%=page%>"><%=all_value
(2,i)%></a></td>
  </tr>
<%
  next

  conn.close
  set conn=nothing
%>
</table>
</td></tr></table>
</center>
</form>
</body>
</html>

반응형
Posted by 친절한 웬디양~ㅎㅎ
|