2014-11-18 2 views
0

안녕하세요 저는 장바구니의 각 항목에 대한 자동 증분 계산 방법을 궁금합니다. 어떻게 장바구니에 각 항목에 대한 자동 증가를하는 프로그래머 두 제품 제품 1 할 것이다, 그래서 만약 [0] 제품 2 할 예정입니다 [1]0에서 시작하는 PHP 카운트

이는 내가 후 오전 결과 ...

pickuppostcode = 2,000 & pickupsuburb = SYDNEY + 시티 & deliverypostcode = 4000 & deliverysuburb = BRISBANE & 입력 [0] = 판지 & 폭 [0] = 40 & 높이 [0] = 35 & 깊이 [0] = 65 & 중량 [0] = 2 & items [0] = 2 & type [1] = BulkyItem & width [1] = 50[1] 3백48경8천55조7천6백36억8천40만3천2백10 높이 45 & 깊이 [1] = 25 & 중량 [1] = 3 & 항목 [1] = 3 & 유형 [2] = BulkyItem & 폭 [2] = 50 & 높이 [2] = 45 &을 = [2] 심도 25 & 중량 [2] = 3 개 & 항목 [2] = 3

(전류)

pickuppostcode = 2,000 & pickupsuburb = SYDNEY + 시티 & deliverypostcode = 4000 & deliverysuburb = BRISBANE & 타입 = [0] = 상자 & 너비 [0] = 40,680,403,210 높이 [0] = 35 & 깊이 [0] 65 & 중량 [0] = 2 개 & 항목 [0] = 2 & 입력 [0] = BulkyItem & 폭 [0] = 50 & 높이 [0] = 45 &을 = [0] = 25 & 무게 [0] = 3 & 항목 [0] = 3

특정 문제 ... (0을 하드 코딩하기 때문에 ... 각 항목에 대해 자동 증가하는 방법을 알아야합니다. Heres는 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"); 
?> 

답변

1

"&width[0]=$width"입니까? 시도해보십시오. "&width[$i]=$width"

+0

두뇌가 퇴색했기 때문에 정확하고 유감스럽게 생각했습니다. 내가 할 수있는 대답으로 받아 들일 것입니다 ... – Bradley

관련 문제