我正在尝试为每对2项商品(每本售价£1.50)打折,但我似乎无法掌握。我从“折扣”和“购物篮”的两个SQL查询/表中得出结果。这是我尝试过的以下内容:
$discount_count[] = 0;
$i = 0;
while ($row2 = mysql_fetch_array($data_set2)) {
if ($row['product'] == $row2['product']) {
foreach ($row2 as $current_row) {
$actual_price = $row['product_cost'] * $row2['quantity'];
$discount_total = round(($actual_price - ($actual_price * ($row2['discount_percent'] / 100))), 2);
$total_price = $discount_total / $row2['quantity'] * $row['quantity'];
$product_total = $row['product_cost'] * $row['quantity'];
if ($i % 2 && $total_price * $row2['quantity'] > $row['product_cost'] * $row2['quantity']){
echo "<br /><br />actual price per 2: £" . $actual_price;
echo "<br />discount total: £" . $discount_total;
echo "<br />actual minus discount: £";
echo $actual_price - $discount_total;
echo "<br />total price: £" . $total_price;
echo "<br />product cost: £" . $product_total;
$discount_count[] = $actual_price - $discount_total;
}
$i++;
}
}
}