lynxvoodoo
Technical User
Hi!
Just out of interest I have been learning how to create a shopping cart, thanks to the various sources available off the net. The problem though is that I have been looking at the follwoing code which displays items from a database BUT how can I limit the number of items displayed per page? e.g 5 items per page with a "Previous" & "Next" button.
Any help would be very much appreciated.
Code --->
<!-- #include file="db.asp" -->
<%
'===================================================
'a.shopKart 2.0
'(c) 1999-2000 Katrien Dermaut De Graeve - URLogy
'
'this page shows products for chosen category
'===================================================
Response.Buffer = true
Dim catid, strcat
catid = Request.QueryString("id"
strcat = Request.QueryString ("cat"
If catid = "" OR (IsNumeric(catid) = false) Then
Response.Redirect "default.asp"
End if
Dim catname, productslist
sub productInfo(connObj,category)
q = chr(34)
set cmd = server.CreateObject("ADODB.Command"
cmd.ActiveConnection = connObj
cmd.CommandText = "qryProdsCategory"
cmd.CommandType = adCmdStoredProc
set param = cmd.CreateParameter("theCategory",adInteger,adParamInput,4)
cmd.Parameters.Append(param)
cmd("theCategory"
= Cint(category)
set rs = server.CreateObject("ADODB.Recordset"
set rs = cmd.Execute
if not rs.EOF then
catname = rs("catdescription"
strHTML = "<table border=0 cellPadding=4 cellSpacing=2 width='100%'>"
strHTML = strHTML & "<tr>"
i = 1
while not rs.EOF
strHTML = strHTML & "<td valign=top>" & vbcrlf
strHTML = strHTML & "<img src=" & q& "images/small/" & rs("cimageurl"
&q& " align=" & q& "left"& q & ">" & vbcrlf
strHTML = strHTML & "<h4>" & rs("cname"
& "</h4>" & vbcrlf
strHTML = strHTML & "<p><font size=-1><a href="&q&"product.asp?id=" & rs("catalogID"
&q&">More >>></a></font></p>" & vbcrlf
strHTML = strHTML & "<p>Price: " & FormatCurrency(rs("cprice"
,2) & "<br>" & vbcrlf
strHTML = strHTML & "<form action="&q&"addprod.asp"&q&" method="&q&"POST"&q&" name=form"&i&" onSubmit="&q& "return checkItems(form"&i&"
" & q&">" & vbcrlf
strHTML = strHTML & "<input type="&q&"hidden"&q&" name="&q&"fproductid"&q&" value="&q & rs("catalogID"
& q&">" & vbcrlf
strHTML = strHTML & "Quantity: <input maxLength="&q&"1"&q&" name="&q&"fquantity"&q&" size=2 value="&q&"1"&q&">" & vbcrlf
strHTML = strHTML & "<input type="&q&"submit"&q&" value="&q&"ORDER"&q&" name="&q&"order"&q&" style="&q&"font-family: Arial; color: #800000; font-weight: bold"&q&">"
strHTML = strHTML & "</form></td>" & vbcrlf
if (i mod 2) = 0 then
strHTML = strHTML & "</tr><tr>" & vbcrlf
end if
i = i + 1
rs.MoveNext
wend
strHTML = strHTML & "<tr></table>"
else
strHTML = "Product information not found."
catname = "Error"
end if
productslist = strHTML
rs.Close
set rs = nothing
set cmd = nothing
end sub
%>
<html>
<head>
<title>Products</title>
<SCRIPT LANGUAGE=javascript>
<!--
function checkItems(formobj)
{
var quant = formobj.fquantity.value
if (isNaN(quant) == true || quant < 1 || quant > 9)
{
alert("Please enter a number between 1 and 9"
;
formobj.fquantity.focus();
return false
}else
{
return true;
}
}
//-->
</SCRIPT>
<link rel="stylesheet" type="text/css" href="eposter.css">
</head>
<body>
<table border="0" width="600" cellpadding="4">
<tr>
<td width="100%" colspan="2" valign="top">
<h3><img src="images/eplogo2.gif" alt="EPoster store" width="187" height="36">
<br><font face="Arial">
<%
'on error resume next
call openConn()
if dbc.errors.count > 0 then
Response.Write "Error accessing database."
else
call productInfo(dbc,catid)
end if
call closeConn()
response.write catname
%>
</font></h3></td>
</tr>
<tr>
<td width="120" bgcolor="#004080" valign="top">
<!--#include file="navleft.htm" --></td>
<td width="480">
<%= productslist %>
</td>
</tr>
</table>
</body>
</html>
Just out of interest I have been learning how to create a shopping cart, thanks to the various sources available off the net. The problem though is that I have been looking at the follwoing code which displays items from a database BUT how can I limit the number of items displayed per page? e.g 5 items per page with a "Previous" & "Next" button.
Any help would be very much appreciated.
Code --->
<!-- #include file="db.asp" -->
<%
'===================================================
'a.shopKart 2.0
'(c) 1999-2000 Katrien Dermaut De Graeve - URLogy
'
'this page shows products for chosen category
'===================================================
Response.Buffer = true
Dim catid, strcat
catid = Request.QueryString("id"
strcat = Request.QueryString ("cat"
If catid = "" OR (IsNumeric(catid) = false) Then
Response.Redirect "default.asp"
End if
Dim catname, productslist
sub productInfo(connObj,category)
q = chr(34)
set cmd = server.CreateObject("ADODB.Command"
cmd.ActiveConnection = connObj
cmd.CommandText = "qryProdsCategory"
cmd.CommandType = adCmdStoredProc
set param = cmd.CreateParameter("theCategory",adInteger,adParamInput,4)
cmd.Parameters.Append(param)
cmd("theCategory"
set rs = server.CreateObject("ADODB.Recordset"
set rs = cmd.Execute
if not rs.EOF then
catname = rs("catdescription"
strHTML = "<table border=0 cellPadding=4 cellSpacing=2 width='100%'>"
strHTML = strHTML & "<tr>"
i = 1
while not rs.EOF
strHTML = strHTML & "<td valign=top>" & vbcrlf
strHTML = strHTML & "<img src=" & q& "images/small/" & rs("cimageurl"
strHTML = strHTML & "<h4>" & rs("cname"
strHTML = strHTML & "<p><font size=-1><a href="&q&"product.asp?id=" & rs("catalogID"
strHTML = strHTML & "<p>Price: " & FormatCurrency(rs("cprice"
strHTML = strHTML & "<form action="&q&"addprod.asp"&q&" method="&q&"POST"&q&" name=form"&i&" onSubmit="&q& "return checkItems(form"&i&"
strHTML = strHTML & "<input type="&q&"hidden"&q&" name="&q&"fproductid"&q&" value="&q & rs("catalogID"
strHTML = strHTML & "Quantity: <input maxLength="&q&"1"&q&" name="&q&"fquantity"&q&" size=2 value="&q&"1"&q&">" & vbcrlf
strHTML = strHTML & "<input type="&q&"submit"&q&" value="&q&"ORDER"&q&" name="&q&"order"&q&" style="&q&"font-family: Arial; color: #800000; font-weight: bold"&q&">"
strHTML = strHTML & "</form></td>" & vbcrlf
if (i mod 2) = 0 then
strHTML = strHTML & "</tr><tr>" & vbcrlf
end if
i = i + 1
rs.MoveNext
wend
strHTML = strHTML & "<tr></table>"
else
strHTML = "Product information not found."
catname = "Error"
end if
productslist = strHTML
rs.Close
set rs = nothing
set cmd = nothing
end sub
%>
<html>
<head>
<title>Products</title>
<SCRIPT LANGUAGE=javascript>
<!--
function checkItems(formobj)
{
var quant = formobj.fquantity.value
if (isNaN(quant) == true || quant < 1 || quant > 9)
{
alert("Please enter a number between 1 and 9"
formobj.fquantity.focus();
return false
}else
{
return true;
}
}
//-->
</SCRIPT>
<link rel="stylesheet" type="text/css" href="eposter.css">
</head>
<body>
<table border="0" width="600" cellpadding="4">
<tr>
<td width="100%" colspan="2" valign="top">
<h3><img src="images/eplogo2.gif" alt="EPoster store" width="187" height="36">
<br><font face="Arial">
<%
'on error resume next
call openConn()
if dbc.errors.count > 0 then
Response.Write "Error accessing database."
else
call productInfo(dbc,catid)
end if
call closeConn()
response.write catname
%>
</font></h3></td>
</tr>
<tr>
<td width="120" bgcolor="#004080" valign="top">
<!--#include file="navleft.htm" --></td>
<td width="480">
<%= productslist %>
</td>
</tr>
</table>
</body>
</html>