ASP using stored procedures to implement data paging

Source: Internet
Author: User
Tags trim
Stored Procedures | pagination | Data first, CREATE TABLE Tiku_koushi



if exists (SELECT * from dbo.sysobjects WHERE id =
OBJECT_ID (N ' [dbo].[ Tiku_koushi] and ObjectProperty
(ID, N ' isusertable ') = 1)
drop table [dbo]. [Tiku_koushi]
Go

CREATE TABLE [dbo]. [Tiku_koushi] (
[ID] [int] IDENTITY (1, 1) not NULL,

[Title] [varchar] (COLLATE)

Chinese_prc_ci_as NULL,

[LIST2_ID] [Char] (a) COLLATE

Chinese_prc_ci_as NULL

) on [PRIMARY]

Go



Second, stored procedure Sp_c


CREATE proc Sp_c
@tablename varchar (50),
@title varchar (250),

@list2_id varchar (50)

As

If @tablename = ' Tiku_koushi '

Select COUNT (*) from Tiku_koushi where title like '% ' + @title + '% ' and list2_id= @list2_id
Go






Third, stored procedure Sp_search_tiku


CREATE PROCEDURE Sp_search_tiku

@tablename varchar (50),

@title varchar (250),

@list2_id varchar (10),

@pagesize int,

@page int

As

If @tablename = ' Tiku_koushi '

Begin

DECLARE @ks int

DECLARE @str varchar (200)

Set @ks = @pagesize * (@page-1)

If not EXISTS (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Temp_table91] and OBJECTPROPERTY (ID, N ' isusertable ') = 1)

Begin

SELECT * into temp_table91 from Tiku_koushi where
Title like '% ' + @title + '% ' and list2_id= @list2_id order
by id DESC

SET ROWCOUNT @pagesize

Set @str = ' SELECT * from temp_table91 where ID
(select Top ' +str (@ks) + ' IDs from temp_table91 ') '

Execute (@str)

drop table Temp_table91

End

End
Go





Four, search_koushi.asp


<!--#include file= "conn.asp"-->
<%
Line=6
If Request ("page") = "" Then
Page=1
Else
Page=request ("page")
End If


If Page<1 Then
Page=1
End If



Title=trim (Request ("title"))
List2_id=trim (Request ("list2_id"))
Set Rs2=conn.execute ("Sp_c ' Tiku_koushi ', '" &title& "', '" &list2_id& "")
Pagecount=cint (rs2 (0) \line)
if (CInt (rs2 (0)) mod line) =0 then
Pagecount=pagecount
Else
Pagecount=pagecount+1
End If


If CInt (page) >=pagecount Then
Page=cint (PageCount)
End If
Str= ""
str=str& "page=" &page& "&title=" &title& "&list2_id=" &list2_id
Set Rs=conn.execute

("Sp_search_tiku ' Tiku_koushi ', '" &title& ", '" &list2_id& "', '" &line& ", '", "&cint page) & "'")
If Rs.eof Then
Response.Write "No Record"





Else
%>


<style type= "Text/css" >

td{font-size:12px;}

A{text-decoration:none;}

</style>
<script language= "JavaScript" >
</script>

<body>
<table width= "518" border= "1" bordercolorlight= "000000"
bordercolordark= "#ffffff"
align= "center" cellpadding= "0" cellspacing= "0" >
<!--dwlayouttable-->

<tr bgcolor= #dfdfdf >

&LT;TD width= "454" align= "center" height=24 valign= "Middle" > Questions </td>

&LT;TD width= "align=" "Center" valign= "Middle" > Delete </td>

</tr>

<% Do until rs.eof%>

<tr height=22>

&LT;TD valign= "Middle" > <a href=void (0) "

ID ")%>&page=<%=page%>&title=<%=title%>&list2_id=<%=list2_id%> ', ', ' width=518
height=160 left=100 ') >

<%=rs ("title")%></a></td>

&LT;TD align= "center" valign= "Middle" > Delete </td>

</tr>

<%





Rs.movenext

Loop

%>

<tr align= "left" valign= "Middle" bgcolor= "Efeff6"
Height=22>

&LT;TD colspan= "2" style= "PADDING-LEFT:6PX;" >

<a href= "Search_koushi.asp?page=<%=1%>&title=<%=title%>&list2_id=<%=list2_id%>" > Home </a> <a
href= "Search_koushi.asp?page=<%=page-1%>&title=<%=title%>&list2_id=<%=list2_id%>" > Prev </a> <a
href= "Search_koushi.asp?page=<%=page+1%>&title=<%=title%>&list2_id=<%=list2_id%>" > next page </a> <a
href= "Search_koushi.asp?page=<%=pagecount%>&title=<%=title%>&list2_id=<%=list2_id%>" > Last </a>

Total <%=pagecount%> page Current page: <%=page%>/<%=pagecount%> page

Total <%=rs2 (0)%> Records </td>

</tr>

</table>

</body>


<%
Rs2.close

Set rs2=nothing

Rs.close

Set rs=nothing

End If

%>




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.