Привет, мне просто интересно, как автоматически увеличивать счет для каждого элемента в корзине покупок. Как автоматическое увеличение для каждого элемента в корзине, так что если два продукта продукта 1 будут [0], а продукт 2 будет [1]
Это результат я после...
pickuppostcode = 2000 & pickupsuburb = СИДНЕЙ + ГОРОД & 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 = СИДНЕЙ + ГОРОД & 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");
?>
Почему "&width[0]=$width"
? try "&width[$i]=$width"