Jump to content

Shopping cart program for multiple-item pick?


richardhsu001

Recommended Posts

Hi,

 

I have seen that most shopping cart program allows a shopper to pick up one item at a time from a list of items, then goes back the list to put another one in the shopping cart, etc.

 

I am interested in finding out if I can use PHP to first display a list of items as below to a customer:

 

ITEM        QTY

 

A                0

B                0

C                0

D                0

 

and then have him/her to change the quantity value for multiple items  and then add all non-zero qty items to the shopping cart together with one " add to shopping cart" button.

 

Please advise...I really appreciate to know if this is doable. If so, any script coding will be appreciated.

Very possible, here is an example:

 

<input type="text" size="4" name="item[A]" />
<input type="text" size="4" name="item[b]" />
<input type="text" size="4" name="item[C]" />

 

Of course I am just showing the simple version, you need to incorperate that to have it dynamic. To access it you would do:

 

<?php
if (isset($_POST)) {
    $item = isset($_POST['item'])?$_POST['item']:array();
    foreach ($item as $itemName => $qty) {
            if ($qty > 0) {
                  // your coding here...
            }
    }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.