Re: Silly varible question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 13/07/06, Ed Curtis <ed@xxxxxxxxxxxxx> wrote:


I know this is probably simple as all get out but it's early and I can't
find an answer anywhere after searching for a while....


I need to assign a number to a variable and then use that variable in a
session to store an array. It's for a shopping cart system I'm building.

What I've got is:

$count = 1; //First item in the cart passed from form to form

$item = array();

$item[] = $_POST['phone'];
$item[] = $_POST['category'];
$item[]  = $_POST['copy'];
$item[] = $_POST['pic_style'];
$item[] = $cost;
$item[] = $image;

session_register('item');

In the session the item is known as 'item'. What I need for it to be is
'item1' so when the customer chooses another product I can increase $count
by 1 and have the next array with values stored as 'item2'.

Thanks for any help,

Ed

First off, don't use session_register, use the $_SESSION superglobal
array, that way you can create:



$_SESSION['count'] = 1

and increment like so:

$_SESSION['count']++

then  you can create the cart like so:

$item{$_SESSION['count']} = array();

does this make sense. Maybe not, but then again I've had far too much
coffee. Make sense to the php gurus out there?




--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux