你好我只想知道如何自动增加购物车中每件商品的数量。 如何自动增加购物车中的每个商品,如果两个产品1将是[0]而产品2将是[1]
这是我追求的结果......
pickuppostcode = 2000&安培; pickupsuburb =悉尼+ CITY&安培; deliverypostcode = 4000&安培; deliverysuburb =布里斯班&安培;类型[0] =纸箱&安培;宽度[0] = 40安培;高度[0] = 35安培;深度[0] = 65安培;重量[0] = 2及项[0] = 2及式[1] = BulkyItem&安培;宽度[1] = 50安培;高度[1] = 45安培;深度[1] = 25安培;重量[1] = 3及项[ 1] = 3及类型[2] = BulkyItem&安培;宽度[2] = 50安培;高度[2] = 45安培;深度[2] = 25安培;重量[2] = 3及项[2] = 3
(当前)
pickuppostcode = 2000&安培; pickupsuburb =悉尼+ CITY&安培; deliverypostcode = 4000&安培; deliverysuburb =布里斯班&安培;类型[0] =纸箱&安培;宽度[0] = 40安培;高度[0] = 35安培;深度[0] = 65安培;重量[0] = 2及项[0] = 2及式[0] = BulkyItem&安培;宽度[0] = 50安培;高度[0] = 45安培;深度[0] = 25安培;重量[0] = 3及项[ 0] = 3
具体问题......(因为我很难编码0.需要知道如何从0开始为购物车中的每件商品自动增加。
//for each product in the cart get the following
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){ //for each product in the cart get the following
$pid=$_SESSION['cart'][$i]['productID']; //productID
$sql="SELECT * FROM products_dimensions WHERE productID=$pid";
$result = mysqli_query($con, $sql) or die(mysqli_error($con)); //run the query
while ($row = mysqli_fetch_array($result)){
/* Dimensions */
$width = $row['width'];
$height = $row['height'];
$depth = $row['depth'];
$weight = $row['weight'];
$type = $row['type'];
$quantity=$_SESSION['cart'][$i]['qty'];
$ego_params .= "&width[0]=$width";
$ego_params .= "&height[0]=$height";
$ego_params .= "&depth[0]=$depth";
$ego_params .= "&weight[0]=$weight";
$ego_params .= "&type[0]=$type";
$ego_params .= "&items[0]=$quantity";
}
}
继承我的洞页面代码..
<?php
session_start();
include "../includes/connect.php";
$calculator_url = "http://www.e-go.com.au/calculatorAPI2";
/* from/to postcodes */
$pickuppostcode = 4508;
$pickupsuburb = urlencode('DECEPTION BAY');
//To Destination
$deliverypostcode = $_POST['postCode'];
$deliverysuburb = urlencode(strtoupper($_POST['suburb']));
$ego_params = "?pickuppostcode=$pickuppostcode&pickupsuburb=$pickupsuburb";
$ego_params .= "&deliverypostcode=$deliverypostcode&deliverysuburb=$deliverysuburb";
//for each product in the cart get the following
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){ //for each product in the cart get the following
$pid=$_SESSION['cart'][$i]['productID']; //productID
$sql="SELECT * FROM products_dimensions WHERE productID=$pid";
$result = mysqli_query($con, $sql) or die(mysqli_error($con)); //run the query
while ($row = mysqli_fetch_array($result))
{
/* Dimensions */
$width = $row['width'];
$height = $row['height'];
$depth = $row['depth'];
$weight = $row['weight'];
$type = $row['type'];
$quantity=$_SESSION['cart'][$i]['qty']; //quantity
$ego_params .= "&width[0]=$width";
$ego_params .= "&height[0]=$height";
$ego_params .= "&depth[0]=$depth";
$ego_params .= "&weight[0]=$weight";
$ego_params .= "&type[0]=$type";
$ego_params .= "&items[0]=$quantity";
}
}
$ego_quote = file($calculator_url . $ego_params);
foreach ($ego_quote as $num=>$quote) {
$quote = trim($quote);
$quote_field = explode("=", $quote);
echo "Field=" . $quote_field[0] . "\tValue=" . $quote_field[1] . "\n";
}
$_SESSION['quote'] = $quote;
echo $ego_params;
//header ("location: ../pages/shoppingcart.php");
?>
答案 0 :(得分:1)
为什么"&width[0]=$width"
?试试"&width[$i]=$width"