question about an declaring array

This is a discussion on question about an declaring array within the PHP Language forums, part of the PHP Programming Forums category; Hello group, I'm trying to implement a shopping cart and currently have a problem as following. First, I will ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-21-2008
amit
 
Posts: n/a
Default question about an declaring array


Hello group,

I'm trying to implement a shopping cart and currently have a problem
as following. First, I will explain. Consider a page as "products.php"

This page has a list of products such as:

product name price button (for each
row)

A 8.00
Add_to_Cart button
B 8.00
Add_to_Cart button
C 12.00
Add_to_Cart button

In this page (product.php) : I have wrapped up the "Add to car" button
in a form where it takes the product id and category id of the product
to a "add2cart.php" using POST method.


<form action="addtocart.php" method="post">
<input type="hidden" name="productid" value="<?php echo
htmlentities($productid); ?>" />
<input type="hidden" name="categoryid" value="<?php echo
htmlentities($selected_category); ?>" />
<input type="submit" value="Add to Cart" />
</form>

In add2car.php I have:

<?php
session_start();

$_SESSION['order'][]= array("order" => array(
'categoryid' => $_POST['categoryid'],
'productid' => $_POST['productid'],
'quantity' => ???? )
);



Ok, the problem is that I don't know how to keep adding added product
into the SESSION array or don't know how to append it to pre-existing
data in $SESSION[]. Currently, If I add the 2nd item the previous
item is replaced.

Sometimes user adds product A and then he/she adds it later on and I
need to keep track of quantity of a specific added item in cart.

1) is the array declared properly base on what I need? how to append
to the array?
2) how to increment the quantify of select product if already exists
in the array?

Thanks.

Reply With Quote
  #2 (permalink)  
Old 07-21-2008
Geoff Berrow
 
Posts: n/a
Default Re: question about an declaring array



I think I'd have a quantity field and then do

$_SESSION['order'][]= array(
'categoryid' => $_POST['categoryid'],
'productid' => $_POST['productid'],
'quantity' => $_POST['quantity'] );


--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:27 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0