|
 |
access_asp thread: Repeating 1st Record
Message #1 by "Lori Bannon" <lori@s...> on Mon, 17 Mar 2003 17:18:33
|
|
When the page displays it repeats the first record as many times as there
are records in the database. It is always the first record. What am I
doing wrong?
Here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html lang="en">
<head>
<title>test</title>
<link rel=stylesheet href="../dealerStylin.css" type="text/css">
<!--#include file="includes/sessionFunctions.asp"-->
<!--#include file="includes/databaseFunctions.asp"-->
<!--#include file="includes/currencyFormat.asp"-->
<!--#include file="includes/stringFunctions.asp"-->
<%
on error resume next
dim strconn, oRs, strSQL
call saveCookie()
pIdProduct = getUserInput(request.queryString("idProduct"),10)
strSQL = "SELECT * FROM tblProducts"
call getFromDB(strSQL, oRs, "viewItem")
pIdProduct = oRs("idProduct")
pManufacturer = oRs("manufacturer")
pModel = oRs("model")
pDetails = oRs("details")
pPrice = oRs("price")
pimageUrl = oRs("imagePath")
%>
</head>
<body bgcolor="#EDEDED" leftmargin="0" topmargin="0" marginheight="0"
marginwidth="0">
<table width="800" border="0" cellspacing="0" cellpadding="0">
<!--//top navigation include//-->
<tr valign="top">
<td colspan="2"><!--#include file="includes/topNav.htm"--></td>
</tr>
<tr valign="top"><!--//left navigation include//--><td><!--#include
file="includes/leftNav.htm"--></td><!--//end of left nav //--><!--// start
of middle content //-->
<td><table border="0" width="500" cellspacing="0" cellpadding="0"
align="center">
<tr valign="top">
<td width="500" nowrap><img src="images/silverTitle.gif" width="295"
height="30" border="0" alt=""></td>
</tr>
<tr valign="top">
<td width="500" align="center" nowrap>
<!--//start of content table//-->
<table width="500" border="0" cellspacing="5" cellpadding="5">
<tr>
<td
class="textMain">¤ <strong>Products</strong></td>
<td align="right" nowrap class="textMain"><a href="trackOrder.asp"
class="color">Track Order</a> <a href="requestInfo.asp"
class="color">Request Info</a></td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td colspan="2">
<%
While Not oRs.eof
%>
<form method="post" action="addToCart.asp" name="addToCart">
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td class="textMain"><strong>Manufacturer: <%=pManufacturer%
></strong></td>
<td class="textMain"><%if pImageUrl<>"" then%>
<img src='../gallery/<%=pImageUrl%>'>
<%else%>
<img src='../gallery/imageNA.gif'>
<%end if%></td>
</tr>
<tr>
<td class="textMain">Model: <%=pModel%></td>
<td class="textMain">Price: <%=pPrice%></td>
</tr>
<tr>
<td colspan="2" class="textMain">Details: <%=pDetails%></td>
</tr>
<tr>
<td colspan="2" class="textMain"><input type="hidden" name="idProduct"
value="<%=pIdProduct%>"><br />
<select name="quantity">
<option value="1"selected>1</option>
<% if pFormQuantity>1 then
for optF=2 to pFormQuantity%>
<option value="<%=optF%>"><%=optF%></option>
<%next
end if%>
</select>
<input alt=Add width="126" height="16" src="images/addcart.gif" type=image
name="add" border="0"></td>
</tr>
</table>
</form>
<%
oRs.movenext
wend
%>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<%
call closeDb()
%>
Here's the databaseFunctions include:
<!--#include file="../includes/adovbs.inc"-->
<%
sub openDB()
if varType(strconn)=0 or varType(strconn)=1 then
' create the connection
set strconn = server.createObject("adodb.connection")
pDatabaseConnectionString = "Driver={Microsoft Access Driver
(*.mdb)};DBQ=" &server.MapPath("../database/dealerArea.mdb")&";"
strconn.Open pDatabaseConnectionString
end if
end sub
sub getFromDB(strSQL, oRs, scriptName)
call openDB()
set oRs = server.createObject("adodb.recordset")
' set locktype
oRs.lockType = adLockReadOnly
' set the cursor
oRs.cursorType = adOpenForwardOnly
oRs.open strSQL, strconn
end sub
sub getFromDBPerPage(strSQL, oRs, scriptName)
call openDB()
set oRs = server.createObject("adodb.recordset")
oRs.cursorLocation = adUseClient
oRs.cacheSize = numPerPage
oRs.open strSQL, conn
end sub
sub getFromDBSeek(strSQL, oRs, scriptName)
call openDB()
set oRs = server.createObject("adodb.recordset")
oRs.cursorType = 3
oRs.lockType = 3
oRs.Open strSQL, conn
end sub
sub updateDB(strSQL, oRs, scriptName)
call openDb()
set oRs=strconn.execute(strSQL)
end sub
function closeDB()
on error resume next
oRs.close
set oRs = nothing
strconn.close
set strconn = nothing
end function
%>
Message #2 by "Zee Computer Consulting" <zee@t...> on Mon, 17 Mar 2003 14:14:29 -0800
|
|
Your variables:
pIdProduct = oRs("idProduct")
pManufacturer = oRs("manufacturer")
pModel = oRs("model")
pDetails = oRs("details")
pPrice = oRs("price")
pimageUrl = oRs("imagePath")
are loaded only once near the top of your program.
You need to move these to inside the "While...Wend" loop so they are
reloaded after the each "MoveNext" statement. You might also want to confirm
that you intend to create multiple forms because you include the <FORM> and
</FORM> tags within that loop.
-- Zee
----- Original Message -----
From: "Lori Bannon" <lori@s...>
To: "Access ASP" <access_asp@p...>
Sent: Monday, March 17, 2003 5:18 PM
Subject: [access_asp] Repeating 1st Record
> When the page displays it repeats the first record as many times as there
> are records in the database. It is always the first record. What am I
> doing wrong?
>
> Here's the code:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
> <html lang="en">
> <head>
> <title>test</title>
>
> <link rel=stylesheet href="../dealerStylin.css" type="text/css">
>
> <!--#include file="includes/sessionFunctions.asp"-->
> <!--#include file="includes/databaseFunctions.asp"-->
> <!--#include file="includes/currencyFormat.asp"-->
> <!--#include file="includes/stringFunctions.asp"-->
>
>
> <%
> on error resume next
>
> dim strconn, oRs, strSQL
>
> call saveCookie()
>
> pIdProduct = getUserInput(request.queryString("idProduct"),10)
>
> strSQL = "SELECT * FROM tblProducts"
>
> call getFromDB(strSQL, oRs, "viewItem")
>
> pIdProduct = oRs("idProduct")
> pManufacturer = oRs("manufacturer")
> pModel = oRs("model")
> pDetails = oRs("details")
> pPrice = oRs("price")
> pimageUrl = oRs("imagePath")
>
> %>
> </head>
>
> <body bgcolor="#EDEDED" leftmargin="0" topmargin="0" marginheight="0"
> marginwidth="0">
>
> <table width="800" border="0" cellspacing="0" cellpadding="0">
>
> <!--//top navigation include//-->
> <tr valign="top">
> <td colspan="2"><!--#include file="includes/topNav.htm"--></td>
> </tr>
>
> <tr valign="top"><!--//left navigation include//--><td><!--#include
> file="includes/leftNav.htm"--></td><!--//end of left nav //--><!--// start
> of middle content //-->
>
> <td><table border="0" width="500" cellspacing="0" cellpadding="0"
> align="center">
>
>
> <tr valign="top">
> <td width="500" nowrap><img src="images/silverTitle.gif" width="295"
> height="30" border="0" alt=""></td>
> </tr>
>
> <tr valign="top">
> <td width="500" align="center" nowrap>
> <!--//start of content table//-->
> <table width="500" border="0" cellspacing="5" cellpadding="5">
>
> <tr>
> <td
> class="textMain">¤ <strong>Products</strong></td>
> <td align="right" nowrap class="textMain"><a href="trackOrder.asp"
> class="color">Track Order</a> <a href="requestInfo.asp"
> class="color">Request Info</a></td>
> </tr>
>
> <tr><td colspan="2"> </td></tr>
>
> <tr>
> <td colspan="2">
> <%
> While Not oRs.eof
> %>
> <form method="post" action="addToCart.asp" name="addToCart">
> <table border="0" cellspacing="5" cellpadding="5">
>
> <tr>
> <td class="textMain"><strong>Manufacturer: <%=pManufacturer%
> ></strong></td>
> <td class="textMain"><%if pImageUrl<>"" then%>
> <img src='../gallery/<%=pImageUrl%>'>
> <%else%>
> <img src='../gallery/imageNA.gif'>
> <%end if%></td>
> </tr>
>
> <tr>
> <td class="textMain">Model: <%=pModel%></td>
> <td class="textMain">Price: <%=pPrice%></td>
> </tr>
>
> <tr>
> <td colspan="2" class="textMain">Details: <%=pDetails%></td>
> </tr>
>
> <tr>
> <td colspan="2" class="textMain"><input type="hidden" name="idProduct"
> value="<%=pIdProduct%>"><br />
>
> <select name="quantity">
> <option value="1"selected>1</option>
> <% if pFormQuantity>1 then
> for optF=2 to pFormQuantity%>
> <option value="<%=optF%>"><%=optF%></option>
> <%next
> end if%>
> </select>
> <input alt=Add width="126" height="16" src="images/addcart.gif" type=image
> name="add" border="0"></td>
> </tr>
>
>
> </table>
>
> </form>
> <%
> oRs.movenext
> wend
> %>
>
> </td>
> </tr>
> </table>
>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> </table>
> </body>
> </html>
> <%
> call closeDb()
> %>
>
>
> Here's the databaseFunctions include:
>
> <!--#include file="../includes/adovbs.inc"-->
>
> <%
>
> sub openDB()
> if varType(strconn)=0 or varType(strconn)=1 then
>
> ' create the connection
> set strconn = server.createObject("adodb.connection")
>
> pDatabaseConnectionString = "Driver={Microsoft Access Driver
> (*.mdb)};DBQ=" &server.MapPath("../database/dealerArea.mdb")&";"
>
> strconn.Open pDatabaseConnectionString
>
> end if
> end sub
>
>
> sub getFromDB(strSQL, oRs, scriptName)
>
> call openDB()
>
> set oRs = server.createObject("adodb.recordset")
>
> ' set locktype
> oRs.lockType = adLockReadOnly
>
> ' set the cursor
> oRs.cursorType = adOpenForwardOnly
>
> oRs.open strSQL, strconn
>
> end sub
>
> sub getFromDBPerPage(strSQL, oRs, scriptName)
>
> call openDB()
>
> set oRs = server.createObject("adodb.recordset")
>
> oRs.cursorLocation = adUseClient
> oRs.cacheSize = numPerPage
>
> oRs.open strSQL, conn
>
> end sub
>
> sub getFromDBSeek(strSQL, oRs, scriptName)
>
> call openDB()
>
> set oRs = server.createObject("adodb.recordset")
> oRs.cursorType = 3
> oRs.lockType = 3
>
> oRs.Open strSQL, conn
>
> end sub
>
> sub updateDB(strSQL, oRs, scriptName)
>
> call openDb()
>
> set oRs=strconn.execute(strSQL)
>
> end sub
>
>
> function closeDB()
> on error resume next
>
> oRs.close
> set oRs = nothing
> strconn.close
> set strconn = nothing
>
> end function
>
> %>
Message #3 by "Lori Bannon" <lori@s...> on Tue, 18 Mar 2003 16:22:07
|
|
thanks...that helped.
> Your variables:
pIdProduct = oRs("idProduct")
pManufacturer = oRs("manufacturer")
pModel = oRs("model")
pDetails = oRs("details")
pPrice = oRs("price")
pimageUrl = oRs("imagePath")
are loaded only once near the top of your program.
You need to move these to inside the "While...Wend" loop so they are
reloaded after the each "MoveNext" statement. You might also want to
confirm
that you intend to create multiple forms because you include the <FORM> and
</FORM> tags within that loop.
-- Zee
----- Original Message -----
From: "Lori Bannon" <lori@s...>
To: "Access ASP" <access_asp@p...>
Sent: Monday, March 17, 2003 5:18 PM
Subject: [access_asp] Repeating 1st Record
> When the page displays it repeats the first record as many times as there
> are records in the database. It is always the first record. What am I
> doing wrong?
>
> Here's the code:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
> <html lang="en">
> <head>
> <title>test</title>
>
> <link rel=stylesheet href="../dealerStylin.css" type="text/css">
>
> <!--#include file="includes/sessionFunctions.asp"-->
> <!--#include file="includes/databaseFunctions.asp"-->
> <!--#include file="includes/currencyFormat.asp"-->
> <!--#include file="includes/stringFunctions.asp"-->
>
>
> <%
> on error resume next
>
> dim strconn, oRs, strSQL
>
> call saveCookie()
>
> pIdProduct = getUserInput(request.queryString("idProduct"),10)
>
> strSQL = "SELECT * FROM tblProducts"
>
> call getFromDB(strSQL, oRs, "viewItem")
>
> pIdProduct = oRs("idProduct")
> pManufacturer = oRs("manufacturer")
> pModel = oRs("model")
> pDetails = oRs("details")
> pPrice = oRs("price")
> pimageUrl = oRs("imagePath")
>
> %>
> </head>
>
> <body bgcolor="#EDEDED" leftmargin="0" topmargin="0" marginheight="0"
> marginwidth="0">
>
> <table width="800" border="0" cellspacing="0" cellpadding="0">
>
> <!--//top navigation include//-->
> <tr valign="top">
> <td colspan="2"><!--#include file="includes/topNav.htm"--></td>
> </tr>
>
> <tr valign="top"><!--//left navigation include//--><td><!--#include
> file="includes/leftNav.htm"--></td><!--//end of left nav //--><!--//
start
> of middle content //-->
>
> <td><table border="0" width="500" cellspacing="0" cellpadding="0"
> align="center">
>
>
> <tr valign="top">
> <td width="500" nowrap><img src="images/silverTitle.gif" width="295"
> height="30" border="0" alt=""></td>
> </tr>
>
> <tr valign="top">
> <td width="500" align="center" nowrap>
> <!--//start of content table//-->
> <table width="500" border="0" cellspacing="5" cellpadding="5">
>
> <tr>
> <td
> class="textMain">¤ <strong>Products</strong></td>
> <td align="right" nowrap class="textMain"><a href="trackOrder.asp"
> class="color">Track Order</a> <a href="requestInfo.asp"
> class="color">Request Info</a></td>
> </tr>
>
> <tr><td colspan="2"> </td></tr>
>
> <tr>
> <td colspan="2">
> <%
> While Not oRs.eof
> %>
> <form method="post" action="addToCart.asp" name="addToCart">
> <table border="0" cellspacing="5" cellpadding="5">
>
> <tr>
> <td class="textMain"><strong>Manufacturer: <%=pManufacturer%
> ></strong></td>
> <td class="textMain"><%if pImageUrl<>"" then%>
> <img src='../gallery/<%=pImageUrl%>'>
> <%else%>
> <img src='../gallery/imageNA.gif'>
> <%end if%></td>
> </tr>
>
> <tr>
> <td class="textMain">Model: <%=pModel%></td>
> <td class="textMain">Price: <%=pPrice%></td>
> </tr>
>
> <tr>
> <td colspan="2" class="textMain">Details: <%=pDetails%></td>
> </tr>
>
> <tr>
> <td colspan="2" class="textMain"><input type="hidden" name="idProduct"
> value="<%=pIdProduct%>"><br />
>
> <select name="quantity">
> <option value="1"selected>1</option>
> <% if pFormQuantity>1 then
> for optF=2 to pFormQuantity%>
> <option value="<%=optF%>"><%=optF%></option>
> <%next
> end if%>
> </select>
> <input alt=Add width="126" height="16" src="images/addcart.gif"
type=image
> name="add" border="0"></td>
> </tr>
>
>
> </table>
>
> </form>
> <%
> oRs.movenext
> wend
> %>
>
> </td>
> </tr>
> </table>
>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> </table>
> </body>
> </html>
> <%
> call closeDb()
> %>
>
>
> Here's the databaseFunctions include:
>
> <!--#include file="../includes/adovbs.inc"-->
>
> <%
>
> sub openDB()
> if varType(strconn)=0 or varType(strconn)=1 then
>
> ' create the connection
> set strconn = server.createObject("adodb.connection")
>
> pDatabaseConnectionString = "Driver={Microsoft Access Driver
> (*.mdb)};DBQ=" &server.MapPath("../database/dealerArea.mdb")&";"
>
> strconn.Open pDatabaseConnectionString
>
> end if
> end sub
>
>
> sub getFromDB(strSQL, oRs, scriptName)
>
> call openDB()
>
> set oRs = server.createObject("adodb.recordset")
>
> ' set locktype
> oRs.lockType = adLockReadOnly
>
> ' set the cursor
> oRs.cursorType = adOpenForwardOnly
>
> oRs.open strSQL, strconn
>
> end sub
>
> sub getFromDBPerPage(strSQL, oRs, scriptName)
>
> call openDB()
>
> set oRs = server.createObject("adodb.recordset")
>
> oRs.cursorLocation = adUseClient
> oRs.cacheSize = numPerPage
>
> oRs.open strSQL, conn
>
> end sub
>
> sub getFromDBSeek(strSQL, oRs, scriptName)
>
> call openDB()
>
> set oRs = server.createObject("adodb.recordset")
> oRs.cursorType = 3
> oRs.lockType = 3
>
> oRs.Open strSQL, conn
>
> end sub
>
> sub updateDB(strSQL, oRs, scriptName)
>
> call openDb()
>
> set oRs=strconn.execute(strSQL)
>
> end sub
>
>
> function closeDB()
> on error resume next
>
> oRs.close
> set oRs = nothing
> strconn.close
> set strconn = nothing
>
> end function
>
> %>
|
|
 |