Hi all,
I am well out of my depth here, but I need to get this done, I have been trying for ages!
It is basically a shopping cart, but I want to be able to do it myself, silly I know!!
The user clicks on a link next to a desired item, this sends them to the cart.php page with that Item_ID in the URL (GET).
I have set up a session in both pages.
In the cart.php page, I have set up a session array, and I want to populate this array with what ever the customer has clicked on, sending the Item_ID into the cart.
Basically, I wrote this, as I am still learning!:
(cart.php)
session_start();
$newitem = $HTTP_GET_VARS['Item_ID'];
if (empty($item)) {$k = 0; $item = $newitem;} else {$k++; $item = $newitem;}
$HTTP_SESSION_VARS['Products']['Item_ID'] = array();
$HTTP_SESSION_VARS['Products']['Item_ID'][$k] = "$item";
Now, I was hoping that everytime the user clicked the "add to basket" link, it would bring a new Item_ID and populate it in the session array, but no, this is not working.
That was the first problem, the second problem is that I want to loop through this array lower down in the page and print out the items relating to each Item_ID stored in the session array.
This means that I need to get a recordset, to retreive the items, and loop through the recordset to get each item where that Item_ID is in the session array.
What SELECT statement do I write to get the records;
SELECT *
FROM item
WHERE Item_ID = '$HTTP_SESSION_VARS[Products][Item_ID][$k]'
doesn't bring back anything at all, so I don't know what to write. Also, I need to loop through this recordset bringing back all the items that are in the basket.
I am sorry that this is quite a heavy problem, I have been reading through my books but I cannot seem to even get the simple stuff working!
I can get one Item_ID into the session array, but when I leave the cart and click another item, it writes over the Item_ID that was previously there.
Thank you for any help!!!
sipps
I am well out of my depth here, but I need to get this done, I have been trying for ages!
It is basically a shopping cart, but I want to be able to do it myself, silly I know!!
The user clicks on a link next to a desired item, this sends them to the cart.php page with that Item_ID in the URL (GET).
I have set up a session in both pages.
In the cart.php page, I have set up a session array, and I want to populate this array with what ever the customer has clicked on, sending the Item_ID into the cart.
Basically, I wrote this, as I am still learning!:
(cart.php)
session_start();
$newitem = $HTTP_GET_VARS['Item_ID'];
if (empty($item)) {$k = 0; $item = $newitem;} else {$k++; $item = $newitem;}
$HTTP_SESSION_VARS['Products']['Item_ID'] = array();
$HTTP_SESSION_VARS['Products']['Item_ID'][$k] = "$item";
Now, I was hoping that everytime the user clicked the "add to basket" link, it would bring a new Item_ID and populate it in the session array, but no, this is not working.
That was the first problem, the second problem is that I want to loop through this array lower down in the page and print out the items relating to each Item_ID stored in the session array.
This means that I need to get a recordset, to retreive the items, and loop through the recordset to get each item where that Item_ID is in the session array.
What SELECT statement do I write to get the records;
SELECT *
FROM item
WHERE Item_ID = '$HTTP_SESSION_VARS[Products][Item_ID][$k]'
doesn't bring back anything at all, so I don't know what to write. Also, I need to loop through this recordset bringing back all the items that are in the basket.
I am sorry that this is quite a heavy problem, I have been reading through my books but I cannot seem to even get the simple stuff working!
I can get one Item_ID into the session array, but when I leave the cart and click another item, it writes over the Item_ID that was previously there.
Thank you for any help!!!
sipps