아는 것이 좋은 것이다.

[ASP] Getrows 페이지 이동, 페이징(2차원 배열) 본문

ASP

[ASP] Getrows 페이지 이동, 페이징(2차원 배열)

start0 2014. 5. 7. 13:53
<!-- #include virtual="db커넥션 인클루드" -->
<!-- 레코드셋이 많을 경우 혹은 DB접근이 많을시엔 속도저하 문제가 올수 있다. DB접근을 한번만 하여서 
DB부하를 최소한으로 줄이고 성능저하를 어느정도 억제할수 있다. 자세한 내용은 검색을 하면 자세히 나옵니다. -->
<html>
<head>
<title>테스트 페이지입니다.</title>
</head>
<script LANGUAGE="JavaScript">
<!--
function paging(page) {

     url="?page=" + page;
     window.open(url,"_self");
}
-->
</script>
<body>
<%
intPageSize = 15   ' 한페이지에서 보여질 수
intBlockPage = 5          '페이지 구분 수 (이전 X개, 다음 X개)
intNowPage = request("page")' 현재페이지
if Len(Trim(intNowPage)) = 0 Then '현재페이지 기본값
intNowPage=1
end if

sql = "SELECT count(*),CEILING(CAST(Count(*) AS FLOAT)/" & intPageSize & ") FROM item"
Set rs = dbconn.Execute(sql)
intTotalCount = rs(0)   ' 전체 자료 수
intTotalPage =  rs(1)
rs.close
Set rs = nothing

Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT TOP " & intNowPage * intPageSize & " * FROM item"
rs.open sql,dbconn

If Not rs.eof then arrRS = rs.getrows()
rs.close
set rs = Nothing
dbconn.close
set dbconn= nothing
%>


<table width="100%" border="1" cellpadding="3" cellspacing="1">
<tr>
    <td width="10%" align="center">번  호</td>
    <td width="75%" align="center">이  름</td>
    <td width="15%" align="center">브랜드</td>
</tr>
<%
If IsArray(arrRS) Then

s_cnt = (intNowPage-1)*intPageSize
e_cnt = s_cnt+intPageSize-1
if e_cnt>intTotalCount then
e_cnt = intTotalCount-1
end if
for i = s_cnt to e_cnt
%>
<tr>
    <td align="center"><%=arrRS(0,i)%></td>
    <td><%=arrRS(1,i)%></td>
    <td><%=arrRS(2,i)%></td>
</tr>
<%
Next
Else
%>
<tr align="center">
    <td colspan="3">데이터가 없습니다.</td>
</tr>
<%
End If
%>
</table>
<table border="0" width="100%">
<!-- 셀렉트 박스를 이용한 페이지 이동 -->
<!-- <tr>
            <td>총자료건수 : <%=intTotalCount%> </td>
            <td align="right">
                현재페이지 :
                <select name="selectpage" onChange="paging(this.options[this.selectedIndex].value,0)">
                <%
                If IsArray(arrRS) Then
                for i = 1 to intTotalPage
                if i = CLng(intNowPage) then
                %>
                <option selected value="<%=i%>"><%=i%></option>
                <%
                else
                %>
                <option value="<%=i%>"><%=i%></option>
                <%
                end if
                Next
                Else
                %>
                <option value="">없음</option>
                <%
                End if
                %>
                </select>
                <font size="3"><b>/<%=intTotalPage%> page</b></font>
            </td>
        </tr> -->
<tr>
    <td valign="middle" width="100%" align="center" colspan="2">
        <%
        intTemp = Int((intNowPage - 1) / intBlockPage) * intBlockPage+ 1
        Response.Write "<a href=""?page=1"" OnFocus='this.blur();' style='text-decoration:none;'>처음</a> "

        If intTemp = 1 Then
        Response.Write "◁ "
        Else
        Response.Write "<a href=""?page=" & intTemp - intBlockPage & """ OnFocus='this.blur();' style='text-decoration:none;'>◀</a> "
        End If

        intLoop = 1

        Do Until intLoop > intBlockPage Or intTemp > intTotalPage
        If intTemp = CInt(intNowPage) Then
        Response.Write "<font style='font-weight:bold; color:#ee6666;'> [" & intTemp & "] </font> "
        Else
        Response.Write"<a href=""?page=" & intTemp & """ OnFocus='this.blur();' style='text-decoration:none;'> [" & intTemp & "] </a> "
        End If
        intTemp = intTemp + 1
        intLoop = intLoop + 1
        Loop

        If intTemp > intTotalPage Then
        Response.Write "▷ "
        Else
        Response.Write"<a href=""?page=" & intTemp & """ OnFocus='this.blur();' style='text-decoration:none;'>▶</a> "
        End If

        Response.Write "<a href=""?page=" & intTotalPage & """ OnFocus='this.blur();' style='text-decoration:none;'>끝</a>"
        %>
    </td>
</tr>
</table>

</body>
</html>
Comments