php从while循环中减去折扣

时间:2017-03-05 10:55:44

标签: php loops points discount

我需要从购物车中减去积分作为折扣,我的购物车可以容纳3家餐馆的商品。

- $ points = 40;

  • 餐厅1

    • item1 $ 5

    • item2 $ 2

- 总计:7美元

  • 餐厅2

    • item1 $ 8

    • item2 $ 4

- 总计:12美元

  • 餐厅3

    • item1 $ 9

- 总计:9美元

现在,我想随机地从点数中减去每个餐馆的金额,并从用户帐户中删除这些点。

在我的例子中,总数是28美元,我的积分是40,所以40-28 =剩余12点 并且购物车总数将为0

这是我的尝试:

$points = 40;
while($row = mysql_fetch_array($sql)){
   $price = $row['price'];
   ...
   ...
   $total = $row['total']; // To here everything is OK.

   $discount = $total - $points; // To subtract 40 for each restaurant and this is not what I want !!
}

0 个答案:

没有答案