0

How to count the item-qty and current code :-

$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,
      );
  }
}

here the array output

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
            )

    )

)

Question :

  1. How to implement other code if item-qty (in all array) is greater than or equal to 3 will use $price['member_price']

let me know :)

2
  • Is there a question? Please clarify what you want to ask. Commented Dec 16, 2009 at 17:21
  • Lots of code... Are we supposed to interpret it? Commented Dec 16, 2009 at 17:23

1 Answer 1

1

I'm guessing you meant the total item-qty of everything?

$qty_sum = 0
 foreach($_SESSION['order'] as $order){
     $qty_sum += $order['item-qty'];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks GSto!. long question but simple answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.