A length and Size for each quantity & Type of product
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13987724/php-shopping-cart-size-and-length-for-each-quantity-of-a-type-of-product">Php Shopping cart - Size and length for each quantity of a type of product</a>  </p>
</blockquote>



<p>Hi i Previously posted this question here and some replies but still cant figure out whats messing my script up....</p>

<p>I Have a shopping cart on page order.php. Its a retail section for a company so that the stores can purchase dresses from that online section. So there are multiple dresses and people can chose any number of dresses. Furthermore on that shopping script there is a place to change the size and length of dresses. </p>

<p>Currently when you order a dress you can select single size and single length per order 
Ex : IF you order 4 Quantity of dress A you can select only one size and length for that dress A.</p>

<p>Now all i want to implement is When you order 4 quantity of dress A, you should be able to choose length and size for each quantity of Dress A means 4 Lengths and 4 Sizes. Maybe this sounds weird but that something i need very desperately</p>

<p>Following is the code :</p>

<p>Session Initialization</p>

<pre><code>session_start();

//Create 'cart' if it doesn't already exist
if (!isset($_SESSION['SHOPPING_CART'])){ $_SESSION['SHOPPING_CART'] = array(); }


//Add an item only if we have the threee required pices of information: name, price, qty
if (isset($_GET['add']) &amp;&amp; isset($_GET['price']) &amp;&amp; isset($_GET['qty']) &amp;&amp; isset($_GET['size'])&amp;&amp; isset($_GET['length'])&amp;&amp; isset($_GET['code']) ){
//Adding an Item
//Store it in a Array
$ITEM = array(
//Item name
'name' =&gt; $_GET['add'],
//Item Price
'price' =&gt; $_GET['price'],
//Qty wanted of item
'qty' =&gt; $_GET['qty'],

'size' =&gt; array_fill(0, $_GET['qty'], $_GET['size']),

    'length' =&gt; array_fill(0, $_GET['qty'], $_GET['length']),

'code' =&gt; $_GET['code']
);
</code></pre>

<p>Part which is supposed to update and store the values of quantity, size and length.</p>

<pre><code>foreach ($_POST['items_qty'] as $itemID =&gt; $qty) {
//If the Qty is "0" remove it from the cart
if ($qty == 0) {
//Remove it from the cart
unset($_SESSION['SHOPPING_CART'][$itemID]);
}
else if($qty &gt;= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;

}
foreach ($_POST['items_size'] as $itemID =&gt; $size) {
//If the Qty is "0" remove it from the cart
if($size &gt;= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['size'] = $size;

}
}
foreach ($_POST['items_length'] as $itemID =&gt; $length) {
//If the Qty is "0" remove it from the cart

//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['length'] = $length;


}
</code></pre>

<p>Thirdly the part that is supposed to display the values : </p>

<p>&lt;</p>

<pre><code>?php
//Print all the items in the shopping cart
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber =&gt; $item) {
?&gt;
&lt;tr align="center" id="item&lt;?php echo $itemNumber; ?&gt;"&gt;
&lt;td&gt;&lt;a href="?remove=&lt;?php echo $itemNumber; ?&gt;"&gt;remove&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $item['name']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $item['price']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;input name="items_qty[&lt;?php echo $itemNumber; ?&gt;]" type="text" id="item&lt;?php echo $itemNumber; ?&gt;_qty" value="&lt;?php echo $item['qty']; ?&gt;" size="2" maxlength="3" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $item['qty'] * $item['price']; ?&gt;&lt;/td&gt;

&lt;td&gt;&lt;select name="items_size[&lt;?php echo $itemNumber; ?&gt;]" value="&lt;?php echo $item['size']; ?&gt;" type="text" id="item&lt;?php echo $itemNumber; ?&gt;_size" &gt;
&lt;option selected="selected" value="&lt;?php echo $item['size']; ?&gt;"&gt;&lt;?php echo $item['size']; ?&gt;&lt;/option&gt;
&lt;option value="2"&gt;2&lt;/option&gt;
&lt;option value="4"&gt;4&lt;/option&gt;
&lt;option value="6"&gt;6&lt;/option&gt;
&lt;option value="8"&gt;8&lt;/option&gt;
&lt;option value="10"&gt;10&lt;/option&gt;
&lt;option value="12"&gt;12&lt;/option&gt;
&lt;option value="14"&gt;14&lt;/option&gt;
&lt;option value="16"&gt;16&lt;/option&gt;
&lt;option value="18"&gt;18&lt;/option&gt;
&lt;option value="20"&gt;20&lt;/option&gt;
&lt;option value="22"&gt;22&lt;/option&gt;
&lt;option value="24"&gt;24&lt;/option&gt;
&lt;option value="26"&gt;26&lt;/option&gt;
&lt;option value="28"&gt;28&lt;/option&gt;
&lt;option value="30"&gt;30&lt;/option&gt;

&lt;/select&gt;
&lt;?php
foreach ($_SESSION['SHOPPING_CART'] as $item_id =&gt; $item)
{
    echo '&lt;p&gt;Name: ' . $item['name'] . ' for ' . $item['price'] . '$&lt;/p&gt;';
    foreach($item['size'] as $j =&gt; $size)
    {
        echo '&lt;p&gt;#' . $j . ': size ' . $size . ', length ' . $item['length'][$j] . '&lt;/p&gt;';
    }
}
?&gt;
&lt;?php
$order=strtotime("now");

if($cntry == "USA" || $cntry =="United States Of America" || $cntry == "America")
{
$price=100;
}
else
{
$price=200;
}

?&gt;
&lt;td&gt;&lt;select name="items_length[&lt;?php echo $itemNumber; ?&gt;]" type="text" select="&lt;?php echo $item['length']; ?&gt;" id="item&lt;?php echo $itemNumber; ?&gt;_length" &gt;
&lt;option selected="selected" value="&lt;?php echo $item['length']; ?&gt;"&gt;&lt;?php echo $item['length']; ?&gt;&lt;/option&gt;
&lt;option value="46"&gt;46&lt;/option&gt;
&lt;option value="48"&gt;48&lt;/option&gt;
&lt;option value="50"&gt;50&lt;/option&gt;


&lt;/select&gt;

&lt;/tr&gt;
&lt;?php
}
?&gt;
</code></pre>

<p>Here</p>

<pre><code> foreach ($_SESSION['SHOPPING_CART'] as $item_id =&gt; $item)
    {
        echo '&lt;p&gt;Name: ' . $item['name'] . ' for ' . $item['price'] . '$&lt;/p&gt;';
        foreach($item['size'] as $j =&gt; $size)
        {
            echo '&lt;p&gt;#' . $j . ': size ' . $size . ', length ' . $item['length'][$j] . '&lt;/p&gt;';
        }
    }
</code></pre>

<p>This part was suggested to me by one of the forum member. </p>

<p>Also after adding the following lines to item array (1st section)</p>

<pre><code>'size' =&gt; array_fill(0, $_GET['qty'], $_GET['size']),

    'length' =&gt; array_fill(0, $_GET['qty'], $_GET['length']),
</code></pre>

<p>When i press update button after changing the quantity it doesnt update.. It stays at one... </p>

<p>Now i really dont know or understand where to add what code. I am confused. Please help me</p>
