Home  >  Article  >  Backend Development  >  购物车的算法

购物车的算法

WBOY
WBOYOriginal
2016-06-13 11:10:461088browse

求一个购物车的算法
当客户将商品加入购物车购买后,如何得到商品的总价,假如 苹果单价10元一个 ,香蕉 5元一个,火龙果8元一个,购买了苹果3个,香蕉2个,火龙果5个,目前数据库是这样设计的 a表放id,商品名称,价格,b表放id(和a表的id相对应),购买的商品个数,如何得到最后的价格呢(最简单高效的办法),我目前的方法是先用多表查询将该客户下的购买的所有数据查询出来,然后在php中用foreach循环数组,然后将价格和个数相乘,最后相加得到结果,感觉效率不好


------解决方案--------------------
该回复于2013-01-11 12:19:36被管理员删除
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn