On Thu, 11 Jan 2001, JB wrote:
> Well... I think I probably owe most of the people on this list some serious cash in
>consulting fees by now. But we're opensource, so I guess I'm off the hook, right? =)
>
> Anyways, another question for you people. I'm on the last leg of designing this
>e-commerce site. All I have left to design is the shopping cart.
>
> How I've set it up to add items is quite simple. The data is posted <add to cart>
>and stored like this:
>
> $cart[$prodid] = $my_qty;
>
> cart is the registered variable in my sessions. prodid is the product id, and my_qty
>is the quantity. now say a user wants 2 items with the id of 111 and 1 item with the
>id of 898. it should have the data stored as so:
>
> $cart[111] = 2
> $cart[898] = 1
>
> now.. had i been more experienced with arrays, this would not be hard. but.. i'm not
>sure when the user goes to check out how to walk through the data.
>
> basically i need to pull out each index (which is the product id number) as it's own
>variable and the qty that corresponds with it as it's own variable.
>
> >From there, although irrelevant to what the array, there variables will be passed
>in a mysql query to get the info to display in the basket (ie- name, description,
>price).
>
> so, i figure i am going to have to loop the array to extract the info. this would
>probably be best since i'm going to be making seperate queries on it as well.
>
> loop until all indexes have been accounted for--->
> get prod id and qty from next instance in array, into $prodid and $qty
> query the db with the prodid
> display results
> end loop -->
>
> so.. i'm fine with the query and display, i just need to know how to get each
>instance into a variable in a loop.
>
> thanks a lot
>
Try:
while (list($prodid, $qty)=each($cart))
{
...
};
--
Ignacio Vazquez-Abrams <[EMAIL PROTECTED]>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]