optellen in asp

Pagina: 1
Acties:
  • 41 views sinds 30-01-2008

  • user643
  • Registratie: Februari 2002
  • Laatst online: 03-09-2025

user643

Sweet Surrender

Topicstarter
Ik ben bezig met een site die een winkelwagen systeem heeft.
De bedoeling is dat de code twee dezelfde producten uit de database, waarvan de aantal producten verschillend kan zijn, bij elkaar optelt en niet onder elkaar zet. |:(

Zie hieronder de code:

<%
'controleer of de winkelwagen leeg is


If IsArray(Session("cart")) = false Then
Dim acart(19,1)
Session("cart") = acart
else

acart=session("cart")
end if
cempty=true
for i=lbound(acart) to ubound(acart)
if acart(i,0)<>"" and acart(i,1)<>"" then
cempty=false
end if
next

%>

--------------------------

<%

'Laat de inhoud van de winkelwagen zien
acart=session("cart")
subtotal=0
for i=lbound(acart) to ubound(acart)

if acart(i,0)<>"" and acart(i,1)<>"" then
set rscart=db.execute("select name,productid,price,saleprice from products where productid=" & acart(i,0))

if rscart("saleprice")="" or rscart("saleprice")=0 then
currentprice=rscart("price")
else
currentprice=rscart("saleprice")
end if

%>

-------------------------------

<td align="left"><font color="#006888" face="Verdana">
'het product wordt uit de database gehaald

<a href="product.asp?productid=<%=rscart("productid") %>"><font size=2>
<%= rscart("name") %></font></a><font size=2>
<br>
</font></font>
</td>

'acart(i,1) is het aantal

<td align="center"><font face=Verdana size=2 color="#006888"><%= acart(i,1) %></font></td>
<td align="right"><font face=Verdana size=2 color="#006888"><%= cursymbol & formatnumber(currentprice)%></font></td>
<td align="right"><font face=Verdana size=2 color="#006888"><%= cursymbol & formatnumber(currentprice * acart(i,1)) %></font></td>
</tr>

'Totaal bedrag
<font face="helvetica" size="3" color="<%= COLdark %>">
<%
subtotal=subtotal+(currentprice * acart(i,1))

end if
next

tax=subtotal*taxrate/100
%>

  • whoami
  • Registratie: December 2000
  • Laatst online: 11:59
Neem de SQL manual er eens bij, en zoek de sectie van de aggregate functions op: daar zie je een functie staan zoals:
code:
1
SUM()

https://fgheysels.github.io/


Dit topic is gesloten.