Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2004, 04:43 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default How to move next Record

I have a page of guest book and I want to display one record at a time and there should be links which will move to next and previus record. I can display the first record and then no idea to how to move next record by cliking on link ?











Numan
--------------------------------------------------
Love is the most precious thing of this world. So find and grab it!
__________________
(*_*)

Numan
--------------------------------------------------
It is not important what you get But important is  how you got it
 
Old August 11th, 2004, 06:50 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,

  You can do with recordset pagesize, cachesize, absolutepage
Every time the page is refreshed and retrives the data.

Or you can do this with XML

Store the data into XML file dynamically and retrieve from xml file.
This is faster.



 
Old August 11th, 2004, 08:20 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 205
Thanks: 0
Thanked 0 Times in 0 Posts
Default

However, storing the xml can mean you are storing a fairly large XML in memory, so you have to Assess the situation before implementing such a solution.
 
Old August 11th, 2004, 08:13 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

hi,

No need to store data initially in XML. Its dynamic, you retrieve from XML instead of having pressure on server every time.



 
Old August 12th, 2004, 04:13 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

Thanks fro all for responding to my problem. But Dare I found the solution which is


<%





strSQL ="SELECT * FROM Guestbook order by Id desc"
Set Recordset1= objDataConn.Execute(strSQL)


Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 5
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

Dim Recordset1_total
Dim Recordset1_first
Dim Recordset1_last

' set the record count
Recordset1_total = Recordset1.RecordCount

' set the number of rows displayed on this page
If (Recordset1_numRows < 0) Then
  Recordset1_numRows = Recordset1_total
Elseif (Recordset1_numRows = 0) Then
  Recordset1_numRows = 1
End If

' set the first and last displayed record
Recordset1_first = 1
Recordset1_last = Recordset1_first + Recordset1_numRows - 1

' if we have the correct record count, check the other stats
If (Recordset1_total <> -1) Then
  If (Recordset1_first > Recordset1_total) Then
    Recordset1_first = Recordset1_total
  End If
  If (Recordset1_last > Recordset1_total) Then
    Recordset1_last = Recordset1_total
  End If
  If (Recordset1_numRows > Recordset1_total) Then
    Recordset1_numRows = Recordset1_total
  End If
End If
%>
<%
Dim MM_paramName
%>
<%
' *** Move To Record and Go To Record: declare variables

Dim MM_rs
Dim MM_rsCount
Dim MM_size
Dim MM_uniqueCol
Dim MM_offset
Dim MM_atTotal
Dim MM_paramIsDefined

Dim MM_param
Dim MM_index

Set MM_rs = Recordset1
MM_rsCount = Recordset1_total
MM_size = Recordset1_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
  MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%>
<%
' *** Move To Record: handle 'index' or 'offset' parameter

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

  ' use index parameter if defined, otherwise use offset parameter
  MM_param = Request.QueryString("index")
  If (MM_param = "") Then
    MM_param = Request.QueryString("offset")
  End If
  If (MM_param <> "") Then
    MM_offset = Int(MM_param)
  End If

  ' if we have a record count, check if we are past the end of the recordset
  If (MM_rsCount <> -1) Then
    If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
      If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full repeat region
        MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
      Else
        MM_offset = MM_rsCount - MM_size
      End If
    End If
  End If

  ' move the cursor to the selected record
  MM_index = 0
  While ((Not MM_rs.EOF) And (MM_index < MM_offset Or MM_offset = -1))
    MM_rs.MoveNext
    MM_index = MM_index + 1
  Wend
  If (MM_rs.EOF) Then
    MM_offset = MM_index ' set MM_offset to the last possible record
  End If

End If
%>
<%
' *** Move To Record: if we dont know the record count, check the display range

If (MM_rsCount = -1) Then

  ' walk to the end of the display range for this page
  MM_index = MM_offset
  While (Not MM_rs.EOF And (MM_size < 0 Or MM_index < MM_offset + MM_size))
    MM_rs.MoveNext
    MM_index = MM_index + 1
  Wend

  ' if we walked off the end of the recordset, set MM_rsCount and MM_size
  If (MM_rs.EOF) Then
    MM_rsCount = MM_index
    If (MM_size < 0 Or MM_size > MM_rsCount) Then
      MM_size = MM_rsCount
    End If
  End If

  ' if we walked off the end, set the offset based on page size
  If (MM_rs.EOF And Not MM_paramIsDefined) Then
    If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
      If ((MM_rsCount Mod MM_size) > 0) Then
        MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
      Else
        MM_offset = MM_rsCount - MM_size
      End If
    End If
  End If

  ' reset the cursor to the beginning
  If (MM_rs.CursorType > 0) Then
    MM_rs.MoveFirst
  Else
    MM_rs.Requery
  End If

  ' move the cursor to the selected record
  MM_index = 0
  While (Not MM_rs.EOF And MM_index < MM_offset)
    MM_rs.MoveNext
    MM_index = MM_index + 1
  Wend
End If
%>
<%
' *** Move To Record: update recordset stats

' set the first and last displayed record
Recordset1_first = MM_offset + 1
Recordset1_last = MM_offset + MM_size

If (MM_rsCount <> -1) Then
  If (Recordset1_first > MM_rsCount) Then
    Recordset1_first = MM_rsCount
  End If
  If (Recordset1_last > MM_rsCount) Then
    Recordset1_last = MM_rsCount
  End If
End If

' set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
  MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
    MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
  End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
    MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
  End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then
  MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
  MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
  MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
  If (firstItem <> "") Then
    MM_joinChar = "&"
  Else
    MM_joinChar = ""
  End If
End Function
%>
<%
' *** Move To Record: set the strings for the first, last, next, and previous links

Dim MM_keepMove
Dim MM_moveParam
Dim MM_moveFirst
Dim MM_moveLast
Dim MM_moveNext
Dim MM_movePrev

Dim MM_urlStr
Dim MM_paramList
Dim MM_paramIndex
Dim MM_nextParam

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' if the page has a repeated region, remove 'offset' from the maintained parameters
If (MM_size > 1) Then
  MM_moveParam = "offset"
  If (MM_keepMove <> "") Then
    MM_paramList = Split(MM_keepMove, "&")
    MM_keepMove = ""
    For MM_paramIndex = 0 To UBound(MM_paramList)
      MM_nextParam = Left(MM_paramList(MM_paramIndex), InStr(MM_paramList(MM_paramIndex),"=") - 1)
      If (StrComp(MM_nextParam,MM_moveParam,1) <> 0) Then
        MM_keepMove = MM_keepMove & "&" & MM_paramList(MM_paramIndex)
      End If
    Next
    If (MM_keepMove <> "") Then
      MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
    End If
  End If
End If

' set the strings for the move to links
If (MM_keepMove <> "") Then
  MM_keepMove = MM_keepMove & "&"
End If

MM_urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="

MM_moveFirst = MM_urlStr & "0"
MM_moveLast = MM_urlStr & "-1"
MM_moveNext = MM_urlStr & CStr(MM_offset + MM_size)
If (MM_offset - MM_size < 0) Then
  MM_movePrev = MM_urlStr & "0"
Else
  MM_movePrev = MM_urlStr & CStr(MM_offset - MM_size)
End If
%>
<html>
<head>


<title>FR FRUITION | GuestBook</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body topmargin="0" bottommargin="0" rightmargin="0" leftmargin="0" class="bg" link="#000000" vlink="#000000" alink="#000000">
<a name="profile"></a>
<form name="client_area">
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
      <td align="center" valign="top">
        <table width="780" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td height="86" align="left" valign="top"><img src="images/header.gif" width="780" height="86"></td>
        </tr>
        <tr>
            <td height="37" align="right" valign="middle" background="images/menu_bg.gif">
              <table width="570" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="117" height="17" class="MenuTitle"><a href="profile.html" class="decor" title="profile">Profile</a></td>
                  <td width="120" class="MenuTitle"><a href="services.html" class="decor" title="services">Services</a></td>
                  <td width="126" class="MenuTitle"><a href="portfolio.html" class="decor" title="portfolio">Portfolio</a></td>
                  <td width="117" class="MenuTitle"><a href="career.html" class="decor" title="Career">Career</a></td>
                  <td width="90" class="MenuTitle"> <a href="contact.html" class="decor" title="contact us">Contact</a></td>
                </tr>
              </table> </td>
        </tr>
      </table>
      <table width="780" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="227" align="left" valign="top"><img src="images/left_top_fill.gif" width="335" height="79"></td>
          <td width="553" align="left" valign="top" background="images/title_bg.gif"><table width="193" border="0" cellspacing="0" cellpadding="0">
              <tr>
                  <td width="193" height="37" align="left" valign="middle" class="fruition"><a href="index.html" title="home page" class="decor3">FRUITION</a></td>
              </tr>
              <tr>
                  <td height="20" align="left" valign="middle" class="PageTitle">guestbook</td>
              </tr>
            </table></td>
        </tr>
      </table>
        <table width="780" border="0" cellspacing="0" cellpadding="0" height="301">
          <tr align="left" valign="top">
            <td width="151" height="301">
              <table width="154" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="154" height="27" align="left" valign="middle" background="images/Untitled1.gif"></td>
                </tr>
              </table>
              <table width="154" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="154" height="29" align="left" valign="middle" background="images/news_heading.gif"><table width="127" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="27" align="left" valign="middle">&nbsp;</td>
                        <td width="100" align="right" valign="middle" class="content">
                          <a href="guestbook.asp" title="sign guestbook" class="decor2">sign
                          guestbook</a></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td height="29" align="left" valign="middle" background="images/news_heading.gif"><table width="127" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="27" align="left" valign="middle">&nbsp;</td>
                        <td width="100" align="right" valign="middle" class="content">
                          view guestbook</td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td align="left" valign="top" background="images/news_bg.gif">&nbsp;</td>
                </tr>
              </table>
            </td>
            <td>
              <table width="100%" border="0" cellspacing="0" cellpadding="0" height="133" style="border-collapse: collapse" bordercolor="#111111">
                <tr>
                  <td width="88%" height="19" align="left" valign="middle">&nbsp;</td>
                  <td width="12%" align="right" valign="top"><img src="images/title_bg2.gif" width="50" height="19"></td>
                </tr>

                <tr background="images/guestbook/viewBookTop.gif">
                  <td height="18" colspan="2" align="left" background="images/guestbook/viewBookTop.gif">&nbsp;</td>
                </tr>
                <tr align="center" valign="middle" background="images/guestbook/viewBookBg.gif">
                  <td height="76" colspan="2">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/guestbook/viewBookBg.gif">
                      <tr>
                        <td height="150" align="center">

<table width="499" border="0" cellpadding="0" cellspacing="0" class="tbl">
                            <%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
                            <tr bgcolor="#E4E4E4">
                              <td width="7" align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading">&nbsp;</td>
                              <td width="61" align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading">Name:</td>
                              <td width="166" bgcolor="#EBEBEB" class="content"><%=(Recordset1.Fields.Item("Name") .Value)%> </td>
                              <td width="68" bgcolor="#EBEBEB" class="contentheaading">E-mail:</td>
                              <td width="197" bgcolor="#EBEBEB" class="content"><a href="mailto:<%=(Recordset1.Fields.Item("Email").V alue)%> " class="decor2"><%=(Recordset1.Fields.Item("Email") .Value)%> </a>
                              </td>
                            </tr>
                            <tr bgcolor="#E4E4E4">
                              <td align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading">&nbsp;</td>
                              <td align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading">City:</td>
                              <td bgcolor="#EBEBEB" class="content"><%=(Recordset1.Fields.Item("City") .Value)%>
                              </td>
                              <td bgcolor="#EBEBEB" class="contentheaading">Country:</td>
                              <td bgcolor="#EBEBEB" class="content"><%=(Recordset1.Fields.Item("Countr y").Value)%>
                              </td>
                            </tr>
                            <tr bgcolor="#E4E4E4">
                              <td align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading">&nbsp;</td>
                              <td align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading">URL:</td>
                              <td bgcolor="#EBEBEB" class="content"><a href="<%=(Recordset1.Fields.Item("URL").Value)%>" class="decor2"><%=(Recordset1.Fields.Item("URL").V alue)%></a>
                              </td>
                              <td bgcolor="#EBEBEB" class="contentheaading">Date:</td>
                              <td bgcolor="#EBEBEB" class="content"><%=(Recordset1.Fields.Item("Dates" ).Value)%>
                              </td>
                            </tr>
                            <tr bgcolor="#E4E4E4">
                              <td align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading">&nbsp;</td>
                              <td align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading">Messege:</td>
                              <td colspan="3" bgcolor="#EBEBEB" class="content"><%=(Recordset1.Fields.Item("Messag e").Value)%>
                              </td>
                            </tr>
                            <tr bgcolor="#E4E4E4">
                              <td colspan="5" align="center" valign="middle" bgcolor="#EBEBEB" class="contentheaading" height="2">&nbsp;</td>
                            </tr>
                            <tr>
                              <td colspan="5" align="left" valign="middle" class="contentheaading"></td>
                            </tr>
                            <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
                          </table>

                          <table width="499" border="0" cellpadding="0" cellspacing="0" class="content">
                            <tr>
                              <td width="188"> <% If MM_offset <> 0 Then %>
                                <a href="<%=MM_movePrev%>" class="decor2">Previous</a>
                                <%else response.Write("Previous") End If ' end MM_offset <> 0 %>
                              </td>
                              <td width="102"> <% If MM_offset <> 0 Then %>
                                <A HREF="<%=MM_moveFirst%>" class="decor2">First</A>
                                <%else response.Write("First") End If ' end MM_offset <> 0 %> </td>
                              <td width="85" align="right"> <% If Not MM_atTotal Then %>
                                <A HREF="<%=MM_moveLast%>" class="decor2">Last</A>
                                <%else response.Write("Last") End If ' end Not MM_atTotal %> </td>
                              <td width="124" align="right"> <% If Not MM_atTotal Then %>
                                <a href="<%=MM_moveNext%>" class="decor2">Next</a>
                                <%else response.Write("Next") End If ' end Not MM_atTotal %> </td>
                            </tr>
                          </table></td>
                      </tr>
                    </table> </td>
                </tr>
                <tr>
                  <td height="19" colspan="2" align="left" valign="middle" background="images/guestbook/viewBookBottom.gif">&nbsp;
                  </td>
                </tr>
              </table>
              <p>&nbsp;</p>
              <p><br>
              </p>
              <table width="100%" border="0" cellspacing="0" cellpadding="0" height="1">
                <tr>
                  <td width="28%" height="1" align="center">&nbsp; </td>
                  <td width="72%" align="right" height="1"> <table width="258" border="0" cellspacing="0" cellpadding="0" height="53">
                      <tr background="images/welcome_bg.gif">
                        <td width="258" height="53" align="center" background="images/footer_fill.gif">&nbsp;
                        </td>
                      </tr>
                    </table></td>
                </tr>
              </table> </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" height="1">
        <tr>
          <td height="1" align="left" valign="top">
          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="780">
            <tr>
              <td width="154">&nbsp;</td>
                <td width="626" height="27" background="images/site_footer.gif">
                  <table width="425" border="0" cellspacing="0" cellpadding="0" height="21">
                    <tr>
                      <td width="113" align="center" valign="middle" class="content" height="21"></td>
                        <td width="312" align="center" valign="bottom" class="content" height="21">&copy;
                          2004 FR Fruition &reg;, All Rights Reserved</td>
                    </tr>
                  </table>
                </td>
            </tr>
          </table>
          </td>
        </tr>
      </table>
      </td>
  </tr>
</table>
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>


Numan
--------------------------------------------------
Love is the most precious thing of this world. So find and grab it!
 
Old August 13th, 2004, 05:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Numan,

Please don't post such long code here, unless asked for. It is really hard to go through the entire code to find whatyou are missing and where you go wrong. Here are some links that does record paging. You can use this as a template and make that work for 1 record per page.

Recordset Paging Sample code

Recordset Paging - output

You can set the following variable to 1 and do the displaying work as you desire.
iPageSize = 10 ' You could easily allow users to change this

Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
move record to another table in same DB Dejitan Classic ASP Basics 2 January 3rd, 2007 07:50 AM
move to particular record number in recordset goodrags VB How-To 3 June 27th, 2006 09:11 PM
Is it possible to move the mouse? nerssi Javascript 2 September 2nd, 2005 07:41 AM
Record locking - user needs the next queued record cbtoolkit SQL Server 2000 0 December 6th, 2004 08:29 AM
Move the form ?? simsimlhr C# 1 April 1st, 2004 02:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.