服務器端我有這樣的表稱爲product
:如何獲得sql列值客戶端的總和?
id | prod_name | prod_price | description | points
如上圖所示,每個產品都有點值有點像星巴克其中每個你買咖啡給你的標籤,一旦你完成一個卡,您可以免費獲得咖啡。我爲我的商店使用了相同的概念。
購買的每件產品都會爲用戶提供其要點。當然,價格的價值根據價格而定。對他來說越高越好。
如何根據他在購物籃/購物車中放置的產品向他展示積累的積分總數?每次他把一個產品放在籃子裏時,總和需要動態升級。我寧願JSTL
或SQL
作爲解決方案,以儘量減少JS
的數量,但我相當開放後者。
因此,這是basket.jsp:
<div class="pointsContainer">
My Reward Points: (<c:out value="${points + points}" /> )
</div>
<div class='block'>
<c:if test="${!empty basket && basket.numberOfItems != 0}">
<h3 class='boardRowHeader'>My Products</h3>
</c:if>
<c:forEach var="basketItem" items="${basket.items}" varStatus="iter">
<c:set var="product" value="${basketItem.product}"/>
<div class="cart_row">
<div class="cart_img"><a href="viewProduct?${product.id}">
<img class="image" alt="" src="${initParam.productGalleryImagePath}${product.id} (1).jpg" />
</div>
<div class="cart_nme"><a class="category_links" href="viewProduct?${product.id}">${product.name}</a></div>
<div class="cart_price">$${product.price}</div>
<div class="cart_update">
${product.points} points
</div>
</div>
</c:forEach>
</div>