Link to home
Start Free TrialLog in
Avatar of claracruz
claracruz

asked on

ASP page turner

Hello experts,

I am trying to do a page turner for an app i am working, on, i had a bit of code, but i have had to change it to suit my site, but now unfortunately, it no longer works properly. The code was writtent to serach throughtthe database and display all records but i amedned the code to dispaly records where critera = variable. This is the problem I have;

if i get for example;

page << 1 of 3 >> for a set of records. and then clikck next >> to go to next record, it then becomes page << 2 of 7 >>.

CODESS BELOW.

ORIGINAL CODE:

Function owPreserve(owVariable,owDefault)
      owTemp = Request.QueryString(owVariable)
            'If the querystring contains any data it is counted as a variable change, if not the old variable is taken from the session or the default assigned
            If Len(owTemp) = 0 Then
                  If Len(Session("user_"&owVariable)) > 0 Then
                        owTemp = Session("user_"&owVariable)
                  Else
                        owTemp = owDefault
                  End If
            End If
      Session("user_"&owVariable) = owTemp
      owPreserve = owTemp
End Function

viewRange = owPreserve("range",1)
varCurPage = owPreserve("page",1)
%>

      <%
globalPageSize = 5
oRs.cursorlocation=3
oRs.cachesize=5

If PageAction = "results" Then
      'Builds the magical search sql query
Else      
      Sql = "SELECT * FROM [product] WHERE [range]="&viewRange&" AND [active]"
End If
oRs.Open Sql, oCn

If Not oRs.Eof Then
      oRs.MoveFirst
       oRs.PageSize = globalPageSize      

      maxpages = cint(oRs.pagecount)
      
      If cint(varCurPage) > maxpages Then
            varCurPage = 1
      End If
      
      oRs.AbsolutePage = varCurPage
      nexpage = varCurPage + 1
      prepage = varCurPage - 1
      Else
            varCurPage = 1
      End If

Do While Not oRs.Eof And Not curRecord = oRs.PageSize

tId = oRs("id")
tTitle = oRs("title")
tFeatures = oRs("features")
tImage = oRs("image")
%>

<table align="center" border="0" cellspacing="10" cellpadding="0">
<tr>
    <td class="PageTurner" colspan="5"><%if cint(varCurPage) > 1 then
                        %>                        
                              <a href="index.asp?page=<%=prepage%>&showtype=<%=showtype%>"><img src="../resources/images/interactive/prevena.gif" width="15" height="14" border="0" align="absmiddle"></a>
                              <%
                        else
                        %>
                              <img src="../resources/images/interactive/prevdis.gif" width="15" height="14" align="absmiddle">
                              <%
                        end if
                        %>
                          Page <%=varCurPage%> of <%If maxpages < 1 Then%>1<%else%><%=maxpages%><%end if%>
                          <%
                        if not cint(varCurPage) < cint(maxpages) then
                        %>
                          <img src="../resources/images/interactive/nextdis.gif" width="15" height="14" align="absmiddle">
                          <%
                        else
                        %>
                          <a href="index.asp?page=<%=nexpage%>&showtype=<%=showtype%>"><img src="../resources/images/interactive/nextena.gif" width="15" height="14" border="0" align="absmiddle"></a>
                          <%
                        end if%></td>
      </tr>
</table>




I HAVE CHANGED THIS TO BECOME THE FOLLOWING;-


<%
viewRange = cint(Request.Form("CID")) <----- I am passing a value to this from a previous page.
%>

Function owPreserve(owVariable,owDefault)
      owTemp = Request.QueryString(owVariable)
            'If the querystring contains any data it is counted as a variable change, if not the old variable is taken from the session or the default assigned
            If Len(owTemp) = 0 Then
                  If Len(Session("user_"&owVariable)) > 0 Then
                        owTemp = Session("user_"&owVariable)
                  Else
                        owTemp = owDefault
                  End If
            End If
      Session("user_"&owVariable) = owTemp
      owPreserve = owTemp
End Function

'viewRange = owPreserve("range",1)<------ commented out as causes the same records to be displayed all the time
varCurPage = owPreserve("page",1)
%>



<%
globalPageSize = 5
rsQuery.cursorlocation=3
rsQuery.cachesize=5

If viewRange = 0 Then
   Sql = "SELECT * FROM [product]"
Else
If PageAction = "results" Then
      'Builds the magical search sql query
Else      
      Sql = "SELECT * FROM [product] WHERE [range]="&viewRange&" AND [active]"
End If
End If
rsQuery.Open Sql, Con

If Not rsQuery.Eof Then
      rsQuery.MoveFirst
       rsQuery.PageSize = globalPageSize      

      maxpages = cint(rsQuery.pagecount)
      
      If cint(varCurPage) > maxpages Then
            varCurPage = 1
      End If
      
      rsQuery.AbsolutePage = varCurPage
      nexpage = varCurPage + 1
      prepage = varCurPage - 1
      Else
            varCurPage = 1
      End If

Do While Not rsQuery.Eof And Not curRecord = rsQuery.PageSize

tId = rsQuery("id")
tTitle = rsQuery("title")
tFeatures =

 rsQuery("features")
tImage = rsQuery("image")
%>

<%
      rsQuery.MoveNext
      curRecord = curRecord + 1
Loop
rsQuery.Close
%>
<table align="center" border="0" cellspacing="10" cellpadding="0">
<tr>
    <td class="PageTurner" colspan="5"><%if cint(varCurPage) > 1 then
                        %>                        
                              <a href="products.asp?page=<%=prepage%>&showtype=<%=showtype%>"><img src="../resources/images/interactive/prevena.gif" width="15" height="14" border="0" align="absmiddle"></a>
                              <%
                        else
                        %>
                              <img src="../resources/images/interactive/prevdis.gif" width="15" height="14" align="absmiddle">
                              <%
                        end if
                        %>
                          Page <%=varCurPage%> of <%If maxpages < 1 Then%>1<%else%><%=maxpages%><%end if%>
                          <%
                        if not cint(varCurPage) < cint(maxpages) then
                        %>
                          <img src="../resources/images/interactive/nextdis.gif" width="15" height="14" align="absmiddle">
                          <%
                        else
                        %>
                          <a href="products.asp?page=<%=nexpage%>&showtype=<%=showtype%>"><img src="../resources/images/interactive/nextena.gif" width="15" height="14" border="0" align="absmiddle"></a>
                          <%
                        end if%></td>
      </tr>
</table>



Thank you

 
Avatar of muzzy2003
muzzy2003

Change:

viewRange = cint(Request.Form("CID")) <----- I am passing a value to this from a previous page.

to

viewRange = cint(Request("CID")) <----- I am passing a value to this from a previous page.

and then change:

                          <a href="products.asp?page=<%=prepage%>&showtype=<%=showtype%>"><img src="../resources/images/interactive/prevena.gif" width="15" height="14" border="0" align="absmiddle"></a>

and similar links to:

                          <a href="products.asp?page=<%=prepage%>&showtype=<%=showtype%>&CID=<%=viewRange>"><img src="../resources/images/interactive/prevena.gif" width="15" height="14" border="0" align="absmiddle"></a>
Basically, the viewRange was passed in the QueryString originally, but you have changed this to post from a form. When you then navigate between the pages, passing data by QueryString, you lose this value. I have put it in, and allowed it to be resolved either from the Form or the QueryString.
Avatar of claracruz

ASKER

hello, thanks for that, but now i et the following error;-

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/shop-gs/products.asp, line 62

rsQuery.AbsolutePage = varCurPage<-------Line 62.
Try rsQuery.AbsolutePage = CInt(varCurPage)

Any better?
still getting

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/shop-gs/products.asp, line 62
Do you get this error when you first go to the page, or when you click on one of the page links?
when i go to the first page
That's before you hit the code I've changed then. Are you sure you're using the right URL? Has your session timed out?
no it hasn't..
ASKER CERTIFIED SOLUTION
Avatar of muzzy2003
muzzy2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i have changed the entire code to the so now works fine!!!! but thanks for all the help