Jump to content

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...
            }
    }
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.