<?php
ob_start();
if(!isset($_SESSION)){ session_start(); } 
 $_SESSION['update_grn'] = array();  
include 'load.php';
if(!isset($_GET['gid'])){
    header('Location: list-grn.php');
}
$gid = $_GET['gid'];


$grniteminfo = mysqli_query($conn, "SELECT * FROM grn_item WHERE grn_no='$gid'");
if ($grniteminfo->num_rows > 0) {
  while($row = $grniteminfo->fetch_assoc()) {
    $productid = $row['product_id'];
    $qty = $row['qty'];
    $discount = $row['discount'];
    $price = $row['price'];
    $found = false;
    foreach ($_SESSION['update_grn'] as $key => $item) {
        if ($item['product_id'] == $productid) {
             $found = true;
              break;
        }
    }
    if (!$found) {
     array_push($cart_items,
                        $cart_items['product_id'] = $productid,
                        $cart_items['discount'] = $discount,
                        $cart_items['quantity'] = $qty, 
                        $cart_items['price'] = $price 
                        
                    );
                    array_push($_SESSION['update_grn'], $cart_items);
                }
  }
}

 header("location: edit-grn.php?gid=".$gid);
?>