Hi, Using the code I got from an article at Called Paging using stored procedures. It works fine, but does not as I see presently have the ability to display the total number of records because it creates a temporary table counts the record from that. I've tried ors.recordcount, pagecount, absolute page
Just having next page is not helpfull enough maybe if I could display how many pages there are or records thre are.
Please can anyone help whose solved this problem in the past or fancies the challenge? I've been onto it for a few days :/
here is the stored procedure :
CREATE PROCEDURE sp_PagedItems
(
@Page int,
@RecsPerPage int
--@iPageCount int
)
AS
-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON
-- Find out where we will start our records from
DECLARE @RecCount int
SELECT @RecCount = @RecsPerPage * @Page + 1
--Create a temporary table
CREATE TABLE #TempItems
(
pID int IDENTITY,
Region varchar(50),
hours varchar(50),
Archived int,
Company varchar(50),
VID int,
CompanyID varchar(50),
Jobtitle varchar(50),
DatepostedUK varchar(50),
Dateposted smalldatetime,
ID int,
industry varchar(50),
)
-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (Region, hours, Archived, Company,VID,CompanyID,Jobtitle,DatepostedUK,Dateposted,ID,industry)
SELECT TBL_Jobtable.Region, TBL_Jobtable.hours,TBL_Jobtable.Archived , TBL_Company2.Company, TBL_Company2.VID, TBL_Jobtable.CompanyID,TBL_Jobtable.Jobtitle, TBL_Jobtable.DatepostedUK,TBL_Jobtable.Dateposted, TBL_Jobtable.ID, TBL_Jobtable.industry FROM TBL_Jobtable
RIGHT JOIN TBL_Company2
ON TBL_Company2.VID = TBL_JobTable.CompanyID
WHERE Archived='0'
-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)
-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
MoreRecords =
(
SELECT COUNT(*)
FROM #TempItems TI
WHERE TI.pID > @LastRec
)
FROM #TempItems
WHERE pID > @FirstRec AND pID < @LastRec
--RETURN @iPageCount
-- Turn NOCOUNT back OFF
SET NOCOUNT OFF
GO
here is the asp code:<html>
<head></head>
<body>
<!-- This assumes you already have a recordset object
explicitly created name objRS -->
<%
set myConn = Server.CreateObject("ADODB.Connection"
myConn.Open Application("fiftyon_ConnectionString"
Set objRS=Server.CreateObject("adodb.Recordset"
'How many records per page do we want to show?
Const iRecordsPerPage = 10
Dim currentPage 'what page are we on??
Dim bolLastPage 'are we on the last page?
if len(Request.QueryString("page") = 0 then
currentPage = 1
else
currentPage = CInt(Request.QueryString("page")
end if
'Show the paged results
strSQL = "sp_PagedItems " & currentPage & "," & iRecordsPerPage
objRS.Open strSQL, myConn
'See if we're on the last page
if Not objRS.EOF then
if CInt(objRS("MoreRecords") > 0 then
bolLastPage = False
else
bolLastPage = True
end if
end if
%>
<P>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 ALIGN=CENTER>
<TR><TH COLSPAN=2 BGCOLOR=NAVY>
<FONT SIZE=+1 COLOR=WHITE>
List of Items
</FONT>
</TH></TR>
<%
Do While Not objRS.EOF %>
<TR><TD ALIGN=LEFT BGCOLOR=GRAY>
</TD><TD ALIGN=CENTER BGCOLOR=GRAY>
<%=(objRS("Hours")%>
</TD></TR>
</TD><TD ALIGN=CENTER BGCOLOR=GRAY>
<%=(objRS("Region")%>
</TD></TR>
</TD><TD ALIGN=CENTER BGCOLOR=GRAY>
<%=(objRS("Company")%>
</TD></TR>
<% objRS.MoveNext
Loop %>
</TABLE>
<P>
<CENTER>
<%
'Only show the previous button if we are NOT on the first page
if currentPage > 1 then %>
<INPUT TYPE=BUTTON VALUE="<< Previous <%=iMaxRecords%> Records"
ONCLICK="document.location.href='pagingmsjones.asp?page=<%=currentPage-1%>'">
<% end if
'Only show the next button if we are NOT on the last page
if Not bolLastPage then %>
<INPUT TYPE=BUTTON VALUE="Next <%=iMaxRecords%> Records >>"
ONCLICK="document.location.href='pagingmsjones.asp?page=<%=currentPage+1%>'">
<% end if %>
</CENTER>
</body>
</html>
Just having next page is not helpfull enough maybe if I could display how many pages there are or records thre are.
Please can anyone help whose solved this problem in the past or fancies the challenge? I've been onto it for a few days :/
here is the stored procedure :
CREATE PROCEDURE sp_PagedItems
(
@Page int,
@RecsPerPage int
--@iPageCount int
)
AS
-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON
-- Find out where we will start our records from
DECLARE @RecCount int
SELECT @RecCount = @RecsPerPage * @Page + 1
--Create a temporary table
CREATE TABLE #TempItems
(
pID int IDENTITY,
Region varchar(50),
hours varchar(50),
Archived int,
Company varchar(50),
VID int,
CompanyID varchar(50),
Jobtitle varchar(50),
DatepostedUK varchar(50),
Dateposted smalldatetime,
ID int,
industry varchar(50),
)
-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (Region, hours, Archived, Company,VID,CompanyID,Jobtitle,DatepostedUK,Dateposted,ID,industry)
SELECT TBL_Jobtable.Region, TBL_Jobtable.hours,TBL_Jobtable.Archived , TBL_Company2.Company, TBL_Company2.VID, TBL_Jobtable.CompanyID,TBL_Jobtable.Jobtitle, TBL_Jobtable.DatepostedUK,TBL_Jobtable.Dateposted, TBL_Jobtable.ID, TBL_Jobtable.industry FROM TBL_Jobtable
RIGHT JOIN TBL_Company2
ON TBL_Company2.VID = TBL_JobTable.CompanyID
WHERE Archived='0'
-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)
-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
MoreRecords =
(
SELECT COUNT(*)
FROM #TempItems TI
WHERE TI.pID > @LastRec
)
FROM #TempItems
WHERE pID > @FirstRec AND pID < @LastRec
--RETURN @iPageCount
-- Turn NOCOUNT back OFF
SET NOCOUNT OFF
GO
here is the asp code:<html>
<head></head>
<body>
<!-- This assumes you already have a recordset object
explicitly created name objRS -->
<%
set myConn = Server.CreateObject("ADODB.Connection"
myConn.Open Application("fiftyon_ConnectionString"
Set objRS=Server.CreateObject("adodb.Recordset"
'How many records per page do we want to show?
Const iRecordsPerPage = 10
Dim currentPage 'what page are we on??
Dim bolLastPage 'are we on the last page?
if len(Request.QueryString("page") = 0 then
currentPage = 1
else
currentPage = CInt(Request.QueryString("page")
end if
'Show the paged results
strSQL = "sp_PagedItems " & currentPage & "," & iRecordsPerPage
objRS.Open strSQL, myConn
'See if we're on the last page
if Not objRS.EOF then
if CInt(objRS("MoreRecords") > 0 then
bolLastPage = False
else
bolLastPage = True
end if
end if
%>
<P>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 ALIGN=CENTER>
<TR><TH COLSPAN=2 BGCOLOR=NAVY>
<FONT SIZE=+1 COLOR=WHITE>
List of Items
</FONT>
</TH></TR>
<%
Do While Not objRS.EOF %>
<TR><TD ALIGN=LEFT BGCOLOR=GRAY>
</TD><TD ALIGN=CENTER BGCOLOR=GRAY>
<%=(objRS("Hours")%>
</TD></TR>
</TD><TD ALIGN=CENTER BGCOLOR=GRAY>
<%=(objRS("Region")%>
</TD></TR>
</TD><TD ALIGN=CENTER BGCOLOR=GRAY>
<%=(objRS("Company")%>
</TD></TR>
<% objRS.MoveNext
Loop %>
</TABLE>
<P>
<CENTER>
<%
'Only show the previous button if we are NOT on the first page
if currentPage > 1 then %>
<INPUT TYPE=BUTTON VALUE="<< Previous <%=iMaxRecords%> Records"
ONCLICK="document.location.href='pagingmsjones.asp?page=<%=currentPage-1%>'">
<% end if
'Only show the next button if we are NOT on the last page
if Not bolLastPage then %>
<INPUT TYPE=BUTTON VALUE="Next <%=iMaxRecords%> Records >>"
ONCLICK="document.location.href='pagingmsjones.asp?page=<%=currentPage+1%>'">
<% end if %>
</CENTER>
</body>
</html>