Forums

This topic is locked

navigation problem

Posted 16 Jul 2007 11:22:26
1
has voted
16 Jul 2007 11:22:26 Nikos Thanos posted:
I'b building a website in Dreamweaver that uses Access to store the paths to images and comments the users are supposed to have added. In the master page where all the images are displayed as thumbs everything works fine.

The detail page shows the chosen photo(from recordset rs2) and its comments ( in a dynamic repeated table from recordset coments) as well as navigation buttons. The navigation buttons work with the displayed photo but i can't get them to load the relevant comment in the table everytime I navigate through the next or previous photo. It keeps on displaying the last record from recordset Comments.

here is the code from the detail page


<pre id=code><font face=courier size=2 id=code>
&lt;%
Dim rs2
Dim rs2_cmd
Dim rs2_numRows

Set rs2_cmd = Server.CreateObject ("ADODB.Command"
rs2_cmd.ActiveConnection = MM_gallery_STRING
rs2_cmd.CommandText = "SELECT * FROM Snowboardingpics ORDER BY picID ASC"
rs2_cmd.Prepared = true

Set rs2 = rs2_cmd.Execute
rs2_numRows = 0
%&gt;
&lt;%
Dim comments__MMColParam
comments__MMColParam = "1"
If (Request.QueryString("picID" &lt;&gt; "" Then
comments__MMColParam = Request.QueryString("picID"
End If
%&gt;
&lt;%
Dim comments
Dim comments_cmd
Dim comments_numRows

Set comments_cmd = Server.CreateObject ("ADODB.Command"
comments_cmd.ActiveConnection = MM_gallery_STRING
comments_cmd.CommandText = "SELECT * FROM Snowboardingpicscomments WHERE picID = ?"
comments_cmd.Prepared = true
comments_cmd.Parameters.Append comments_cmd.CreateParameter("param1", 5, 1, -1, comments__MMColParam) ' adDouble

Set comments = comments_cmd.Execute
comments_numRows = 0
%&gt;
&lt;%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
comments_numRows = comments_numRows + Repeat1__numRows
%&gt;
&lt;%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

Dim rs2_total
Dim rs2_first
Dim rs2_last

' set the record count
rs2_total = rs2.RecordCount

' set the number of rows displayed on this page
If (rs2_numRows &lt; 0) Then
rs2_numRows = rs2_total
Elseif (rs2_numRows = 0) Then
rs2_numRows = 1
End If

' set the first and last displayed record
rs2_first = 1
rs2_last = rs2_first + rs2_numRows - 1

' if we have the correct record count, check the other stats
If (rs2_total &lt;&gt; -1) Then
If (rs2_first &gt; rs2_total) Then
rs2_first = rs2_total
End If
If (rs2_last &gt; rs2_total) Then
rs2_last = rs2_total
End If
If (rs2_numRows &gt; rs2_total) Then
rs2_numRows = rs2_total
End If
End If
%&gt;
&lt;%
' *** Recordset Stats: if we don't know the record count, manually count them

If (rs2_total = -1) Then

' count the total records by iterating through the recordset
rs2_total=0
While (Not rs2.EOF)
rs2_total = rs2_total + 1
rs2.MoveNext
Wend

' reset the cursor to the beginning
If (rs2.CursorType &gt; 0) Then
rs2.MoveFirst
Else
rs2.Requery
End If

' set the number of rows displayed on this page
If (rs2_numRows &lt; 0 Or rs2_numRows &gt; rs2_total) Then
rs2_numRows = rs2_total
End If

' set the first and last displayed record
rs2_first = 1
rs2_last = rs2_first + rs2_numRows - 1
If (rs2_first &gt; rs2_total) Then rs2_first = rs2_total
If (rs2_last &gt; rs2_total) Then rs2_last = rs2_total

End If
%&gt;
&lt;%
Dim MM_paramName
%&gt;
&lt;%
' *** 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 = rs2
MM_rsCount = rs2_total
MM_size = rs2_numRows
MM_uniqueCol = "picID"
MM_paramName = "picID"
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName &lt;&gt; "" Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) &lt;&gt; ""
End If
%&gt;
&lt;%
' *** Move To Specific Record: handle detail parameter

If (MM_paramIsDefined And MM_rsCount &lt;&gt; 0) Then

' get the value of the parameter
MM_param = Request.QueryString(MM_paramName)

' find the record with the unique column value equal to the parameter value
MM_offset = 0
Do While (Not MM_rs.EOF)
If (CStr(MM_rs.Fields.Item(MM_uniqueCol).Value) = MM_param) Then
Exit Do
End If
MM_offset = MM_offset + 1
MM_rs.MoveNext
Loop

' if not found, set the number of records and reset the cursor
If (MM_rs.EOF) Then
If (MM_rsCount &lt; 0) Then
MM_rsCount = MM_offset
End If
If (MM_size &lt; 0 Or MM_size &gt; MM_offset) Then
MM_size = MM_offset
End If
MM_offset = 0

' reset the cursor to the beginning
If (MM_rs.CursorType &gt; 0) Then
MM_rs.MoveFirst
Else
MM_rs.Close
MM_rs.Open
End If
End If

End If
%&gt;
&lt;%
' *** Move To Record: handle 'index' or 'offset' parameter

if (Not MM_paramIsDefined And MM_rsCount &lt;&gt; 0) then

' use index parameter if defined, otherwise use offset parameter
r = Request.QueryString("index"
If r = "" Then r = Request.QueryString("offset"
If r &lt;&gt; "" Then MM_offset = Int(r)

' if we have a record count, check if we are past the end of the recordset
If (MM_rsCount &lt;&gt; -1) Then
If (MM_offset &gt;= MM_rsCount Or MM_offset = -1) Then ' past end or move last
If ((MM_rsCount Mod MM_size) &gt; 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
i = 0
While ((Not MM_rs.EOF) And (i &lt; MM_offset Or MM_offset = -1))
MM_rs.MoveNext
i = i + 1
Wend
If (MM_rs.EOF) Then MM_offset = i ' set MM_offset to the last possible record

End If
%&gt;
&lt;%
' *** 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 &lt; 0 Or MM_index &lt; 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 &lt; 0 Or MM_size &gt; 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 &gt; MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) &gt; 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 &gt; 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 &lt; MM_offset)
MM_rs.MoveNext
MM_index = MM_index + 1
Wend
End If
%&gt;
&lt;%
' *** 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
i = MM_offset
While (Not MM_rs.EOF And (MM_size &lt; 0 Or i &lt; MM_offset + MM_size))
MM_rs.MoveNext
i = i + 1
Wend

' if we walked off the end of the recordset, set MM_rsCount and MM_size
If (MM_rs.EOF) Then
MM_rsCount = i
If (MM_size &lt; 0 Or MM_size &gt; MM_rsCount) Then MM_size = MM_rsCount
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 &gt; MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) &gt; 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 &gt; 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If

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

' set the first and last displayed record
rs2_first = MM_offset + 1
rs2_last = MM_offset + MM_size

If (MM_rsCount &lt;&gt; -1) Then
If (rs2_first &gt; MM_rsCount) Then
rs2_first = MM_rsCount
End If
If (rs2_last &gt; MM_rsCount) Then
rs2_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 &lt;&gt; -1 And MM_offset + MM_size &gt;= MM_rsCount)
%&gt;
&lt;%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName &lt;&gt; "" Then MM_removeList = MM_removeList & "&" & MM_paramName & "="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_keepNone=""

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

' add the Form variables to the MM_keepForm string
For Each Item In Request.Form
NextItem = "&" & Item & "="
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(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 &lt;&gt; "" Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
if (MM_keepURL &lt;&gt; "" Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm &lt;&gt; "" Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)

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

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' if the page has a repeated region, remove 'offset' from the maintained parameters
If (MM_size &gt; 0) Then
MM_moveParam = "offset"
If (MM_keepMove &lt;&gt; "" Then
params = Split(MM_keepMove, "&"
MM_keepMove = ""
For i = 0 To UBound(params)
nextItem = Left(params(i), InStr(params(i),"=" - 1)
If (StrComp(nextItem,MM_moveParam,1) &lt;&gt; 0) Then
MM_keepMove = MM_keepMove & "&" & params(i)
End If
Next
If (MM_keepMove &lt;&gt; "" 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 &lt;&gt; "" Then MM_keepMove = MM_keepMove & "&"
urlStr = Request.ServerVariables("URL" & "?" & MM_keepMove & MM_moveParam & "="
MM_moveFirst = urlStr & "0"
MM_moveLast = urlStr & "-1"
MM_moveNext = urlStr & Cstr(MM_offset + MM_size)
prev = MM_offset - MM_size
If (prev &lt; 0) Then prev = 0
MM_movePrev = urlStr & Cstr(prev)
%&gt;
</font id=code></pre id=code>

Reply to this topic