Domanda

Come contare il item-qty e codice corrente: -

$q = $_POST['item-qty'];
$i = count($q);
$k = 0;

while ($k < $i) {
  $select = 'SELECT * FROM location';
  $query = $db->rq($select);
  $price = $db->fetch($query);

  if ($_POST['item-qty'][$k] < 3) {

      $get = $price['normal_price'];
      $price = $get * $_POST['item-qty'][$k];

      $_SESSION['order'][$_POST['item-id'][$k]] = array(
      "item-id" => $_POST['item-id'][$k],
      "item-qty" => $_POST['item-qty'][$k],
      "item-name" => $_POST['item-name'][$k],
      "item-price" => $price,
       );

  } else {

      $get = $price['member_price'];
      $price = $get * $_POST['item-qty'][$k];

      $_SESSION['order'][$_POST['item-id'][$k]] = array(
      "item-id" => $_POST['item-id'][$k],
      "item-qty" => $_POST['item-qty'][$k],
      "item-name" => $_POST['item-name'][$k],
      "item-price" => $price,
      );
  }
}

qui l'output array

Array
(
[order] => Array
    (
        [1] => Array
            (
                [item-id] => 1
                [item-qty] => 1
                [item-name] => Adidas
                [item-price] => 100
            )

        [2] => Array
            (
                [item-id] => 2
                [item-qty] => 1
                [item-name] => Nike
                [item-price] => 150
            )

    )

)

Domanda:

  1. Come implementare altro codice se item-qty (in tutto array) è maggiore o uguale a 3 utilizzerà $price['member_price']

fatemi sapere:)

È stato utile?

Soluzione

Sto indovinando che volevi dire l'elemento-qty totale di tutto ciò?

$qty_sum = 0
 foreach($_SESSION['order'] as $order){
     $qty_sum += $order['item-qty'];
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top