Link to home
Start Free TrialLog in
Avatar of jay_eire
jay_eireFlag for United States of America

asked on

Go To Detail Page Passing Values but not getting picked up correctly on Detail Page

Hi Guys,
I have two pages the first called main_view.asp and the second is called Sub_View.asp i am using repated regions on both pages.

on the main_view.asp page i am using a "Go To Detail Page" link to link to Sub_View.asp im passing the CATID to this page to select everything from the table tblSubCat where the ID is equal to 3 for example, depending on which category the user selects on main_view.asp.

the SQL bit works, and when i test it in the recordset window in the dreamweaver it works, BUT when i go to my browser and test it, it keeps returning back the first record in the database everytime! no matter what link i click, even though in the browser address bar the URL changes eg: http://mysite/Sub_View.asp?CatID=3 

please help!

Thanks
Jay Eire
(<>..<>)


************************************ Main View ************************************

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/DB_Connect.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_DB_Connect_STRING
Recordset1.Source = "SELECT * FROM dbo.tblCat ORDER BY CatDesc ASC"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
Dim MM_paramName
%>
<%
' *** 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
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Main View</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr bgcolor="#CCCCCC">
    <td><strong><font color="#666666">ID</font></strong></td>
    <td><strong><font color="#666666">Description</font></strong></td>
    <td><font color="#666666">&nbsp;</font></td>
  </tr>
  <%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
  <tr>
    <td width="18%"><%=(Recordset1.Fields.Item("CatID").Value)%></td>
    <td width="65%"><%=(Recordset1.Fields.Item("CatDesc").Value)%></td>
    <td width="17%"><A HREF="sub_view.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "CatID=" & Recordset1.Fields.Item("CatID").Value %>">View</A></td>
  </tr>
  <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
</table>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>




************************************ Sub View ************************************
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/DB_Connect.asp" -->
<%
Dim Recordset2__MMColParam
Recordset2__MMColParam = "1"
If (Request.QueryString("CatFID") <> "") Then
  Recordset2__MMColParam = Request.QueryString("CatFID")
End If
%>
<%
Dim Recordset2
Dim Recordset2_numRows

Set Recordset2 = Server.CreateObject("ADODB.Recordset")
Recordset2.ActiveConnection = MM_DB_Connect_STRING
Recordset2.Source = "SELECT * FROM dbo.tblSubCat WHERE CatFID = " + Replace(Recordset2__MMColParam, "'", "''") + " ORDER BY SubCatDesc ASC"
Recordset2.CursorType = 0
Recordset2.CursorLocation = 2
Recordset2.LockType = 1
Recordset2.Open()

Recordset2_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset2_numRows = Recordset2_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Sub View</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr bgcolor="#CCCCCC">
    <td><strong><font color="#666666">SubID</font></strong></td>
    <td><strong><font color="#666666">Sub Description</font></strong></td>
    <td><font color="#666666">&nbsp;</font></td>
  </tr>
  <%
While ((Repeat1__numRows <> 0) AND (NOT Recordset2.EOF))
%>
  <tr>
    <td><%=(Recordset2.Fields.Item("SubCatID").Value)%></td>
    <td><%=(Recordset2.Fields.Item("SubCatDesc").Value)%></td>
    <td>View</td>
  </tr>
  <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset2.MoveNext()
Wend
%>
</table>
</body>
</html>
<%
Recordset2.Close()
Set Recordset2 = Nothing
%>
ASKER CERTIFIED SOLUTION
Avatar of rockmansattic
rockmansattic

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
Avatar of rockmansattic
rockmansattic

your main page is sending a CatID, but your sub_page is looking for CatDIF.


rockman
Avatar of jay_eire

ASKER

yes i know, its ment to do that CATFID is the foreign key to CATID.......
No..
the sub page is searching the database with the wrong variable.
the url var is CatID
the searching var is CatFID

when you get to the sub page, since there is NO CATFID variable, the default is 1, which is why you are getting the first record every time.

change the url to this and see

http://mysite/Sub_View.asp?CatFID=3 

Rockman
my fault, i see what your getting at now, thank for your help man!
no problem, sometimes it is hard to explain without moving may hands wildly in the air.

Rockman